我正在嘗試使用 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 關注
- 168 瀏覽
添加回答
舉報
0/150
提交
取消