dtbiszu7724 2018-02-05 13:07
浏览 40
已采纳

获取URL中的片段值

sample code

func main() {
    fmt.Print("starting box web server...")
    http.HandleFunc("/", landing)
    http.HandleFunc("/handle", handler)
    http.ListenAndServe(connector_port, nil)
}
func landing(w http.ResponseWriter, r *http.Request) {
    fmt.Println("redirecting to login for authentication...")
    http.Redirect(w, r, "http://*****urlfortoken", http.StatusFound)
}
func handler(w http.ResponseWriter, r *http.Request) {
    bodyresnew_folder, _ := ioutil.ReadAll(r.Body)
    fmt.Println("response Body:", string(bodyresnew_folder))
    fmt.Println("1", r.GetBody)
    fmt.Println("2", r.URL.String())
    fmt.Println("3", r.URL.Fragment)
    fmt.Println("4", r.URL.Query().Get("access_token"))
    fmt.Println("inside handle function,", r.Form.Get("access_token"))
    fmt.Println("finished processing all files please close this server manually")
}

I tried the code above to get fragment from an URL but was unsuccessful.

Example URL used is: http://localhost:8080/handle#access_token=*1234$111&token_type=bearer&expires_in=3600&scope=onedrive.readwrite&user_id=hashed

Now, for such URL, I want to get the value of fragment access_token in the handler function which is basically an http handler.

</div>
  • 写回答

2条回答 默认 最新

  • doubu1950 2018-02-06 14:21
    关注

    Shameless copy from: https://github.com/OneDrive/onedrive-api-docs/issues/9

    OneDrive uses Microsoft account as its identity provider, which implements the OAuth 2.0 protocol. Per the OAuth 2.0 spec, the access token is returned in the fragment component of the redirect uri when the response type is set to "token". You can read more about it at https://tools.ietf.org/html/rfc6749#section-4.2.2.

    If you would like the access token in the query parameter, consider using the "code" flow.

    Here you will find information about this 'code flow': https://docs.microsoft.com/en-us/onedrive/developer/rest-api/getting-started/msa-oauth

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP