I have a function for check url like that:
func Checkurl(url string) {
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
resp, err := client.Get(url)
In error var: unexpected EOF
In tcpdump i see redirect and Connection close:
15:53:41.510722 IP (tos 0x0, ttl 248, id 18315, offset 0, flags [none], proto TCP (6), length 123)
XXX.XXX.XXX.XXX.80 > XXX.XXX.XXX.XXX.53618: Flags [F.], cksum 0xb96f (correct), seq 85:168, ack 1, win 5840, length 83: HTTP, length: 83
HTTP/1.1 302 Moved Temporarily
Location: http://XXX.XXX.XXX.XXX
Connection: close
How i can get Location?
Use Response.Location
function.
newUrl, err := resp.Location()
Type Client
has support for redirection. See CheckRedirect
field. This might be a better tool for handling redirects, depending on what you are trying to achieve.
Use client.Do
for Request
object method
client := &http.Client{}
req, err := http.NewRequest("GET", url, nil)
// check error
resp, err := client.Do(req)
// check error
newURL, err := resp.Location()
// check error
The default client handles redirections by default, therefore I would check the response of the final destination. It is most probably the root cause of your problem.