How to retrieve the final URL destination while using the http package in Go? -
most sites redirect url during request. example: http://example.com might
might redirects http://mobile.example.com
is there way retrieve final destination? in case of curl
, call effective url
.
for example,
package main import ( "fmt" "net/http" ) func main() { geturl := "http://pkgdoc.org/" fmt.println("geturl:", geturl) resp, err := http.get(geturl) if err != nil { fmt.println(err) return } finalurl := resp.request.url.string() fmt.println("finalurl:", finalurl) }
output:
geturl: http://pkgdoc.org/ finalurl: http://godoc.org/
Comments
Post a Comment