【发布时间】:2018-02-05 13:07:13
【问题描述】:
示例代码
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")
}
我尝试使用上面的代码从 URL 中获取片段,但没有成功。
使用的示例 URL 是:http://localhost:8080/handle#access_token=*1234$111&token_type=bearer&expires_in=3600&scope=onedrive.readwrite&user_id=hashed
现在,对于这样的 URL,我想在基本上是一个 http 处理程序的 handler 函数中获取片段 access_token 的值。
【问题讨论】:
-
片段不发送到服务器。所以你不能“得到”它们:传入的请求不包含片段。
-
@Volker 哦谢谢你的信息
标签: go httphandler