Last active
August 29, 2015 14:06
-
-
Save hamdouni/0488bf6dfa1a7f9db142 to your computer and use it in GitHub Desktop.
Golang http get without following redirection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"log" | |
"net/http" | |
) | |
func main() { | |
req, err := http.NewRequest("GET", "http://google.com/", nil) | |
if err != nil { | |
log.Fatalf("error new request: %v", err) | |
} | |
res, err := http.DefaultTransport.RoundTrip(req) | |
if err != nil { | |
log.Fatalf("error default transport: %v", err) | |
} | |
defer res.Body.Close() | |
contents, err := ioutil.ReadAll(res.Body) | |
if err != nil { | |
log.Fatalf("error reading content: %v", err) | |
} | |
fmt.Printf("contents: %s\nurl: %s\nstatus: %s\n", string(contents), res.Request.URL.String(), res.Status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment