http.Client
提供了一種通過CheckRedirect
成員來控制該響應的可能性。
從上面的鏈接:
// CheckRedirect specifies the policy for handling redirects.
// If CheckRedirect is not nil, the client calls it before
// following an HTTP redirect. The arguments req and via are
// the upcoming request and the requests made already, oldest
// first. If CheckRedirect returns an error, the Client's Get
// method returns both the previous Response and
// CheckRedirect's error (wrapped in a url.Error) instead of
// issuing the Request req.
//
// If CheckRedirect is nil, the Client uses its default policy,
// which is to stop after 10 consecutive requests.
ct func(req *Request, via []*Request) error
聲明:未測試。
另請參閱:http://stackoverflow.com/questions/23297520/how-can-i-make-the-go-http-client-not-follow-redirects-automatically http://stackoverflow.com/問題/ 35089052 /如何獲取重定向網址而不是頁面內容在golang –
YEP鏈接使它 – Elliott