Open anpez opened 8 years ago
I think that has nothing to do with gorequest directly, cuz it's using the net/http package underneath. General speaking all headers get lost at a redirect, see https://github.com/golang/go/issues/4800 There is also mentioned, that this behaviour can be controlled by CheckRedirect-function.
edit
see example below
request := gorequest.New()
_, body, _ := request.Get(url).
RedirectPolicy(func(req gorequest.Request, via []gorequest.Request) error {
for attr, val := range via[0].Header {
if _, ok := req.Header[attr]; !ok {
req.Header[attr] = val
}
}
return nil
}).
Set("User-Agent", useragent).
End()
log.Println(body)
Thanks! That works. It should be in the doc, I think.
Sorry for discussing unrelated stuff here. But I don't know how to reach you, @fraenky8. Could you send an email to me (parnurzeal at gmail)? I would like to consult you about this GoRequest.
I tried to reproduce the issue but this seems to no longer be an issue as of today, with Go 1.9.
How to get just 301 status code instead of error?
I am creating a new agent like so:
gorequest. New(). Get(url). Set("User-Agent", useragent). EndBytes()
When url returns 301 and the http client re-requests for the new location, the user agent is not being set.