In golang, how to determine the final URL after a series of redirects?

package main

import (
    "fmt"
    "log"
    "net/http"
)

func main() {
    resp, err := http.Get("http://stackoverflow.com/q/16784419/727643")
    if err != nil {
        log.Fatalf("http.Get => %v", err.Error())
    }

    // Your magic function. The Request in the Response is the last URL the
    // client tried to access.
    finalURL := resp.Request.URL.String()

    fmt.Printf("The URL you ended up at is: %v\n", finalURL)
}

Output:

The URL you ended up at is: http://stackoverflow.com/questions/16784419/in-golang-how-to-determine-the-final-url-after-a-series-of-redirects

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)