3

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.

4

1 回答 1

4

例如,

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/
于 2013-05-14T01:49:20.427 回答