Most sites redirect to another URL during a request. For example: http://example.com might
might redirects to http://mobile.example.com
Is there a way to retrieve the final destination? In case of cURL
, they call this the effective URL
.
Most sites redirect to another URL during a request. For example: http://example.com might
might redirects to http://mobile.example.com
Is there a way to retrieve the final destination? In case of cURL
, they call this the effective URL
.
例如,
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)
}
输出:
getURL: http://pkgdoc.org/
finalURL: http://godoc.org/