我正在尝试使用 HTTP 发出请求。Go 中的 Get(url),我想在浏览器中打开响应。我正在使用浏览器。打开URL()来启动系统浏览器,但我不知道如何获取响应网址。在Python中,使用请求库,它是响应对象的一个属性。我可以在浏览器(使用浏览器库)中获取并打开它,如下所示:response = requests.get(endpoint)browser.open(response.url)如何在 Go 中使用 http/net 库来实现此目的?响应对象是不包含该属性的结构。我正在尝试调用Spotify API来验证应用程序,这需要打开浏览器窗口供用户输入。到目前为止,我已经得到了这个:func getAuth(endpoint *url.Url) { request, _ := http.NewRequest("GET", endpoint.string(), nil) client := &http.Client{} resp, err := client.Do(request) if err != nil { panic(err) } headers := resp.Header page, _ := ioutil.ReadAll(resp.Body)在哪里可以获得响应 URL,或者如何处理响应,以便在浏览器中打开它?
2 回答

POPMUISE
TA贡献1765条经验 获得超5个赞
如果有重定向,Go 将更新响应上的结构。Request
resp.Request.URL是你要找的。
// Request is the request that was sent to obtain this Response.
// Request's Body is nil (having already been consumed).
// This is only populated for Client requests.
Request *Request
- 2 回答
- 0 关注
- 170 浏览
添加回答
举报
0/150
提交
取消