Skip to content

Instantly share code, notes, and snippets.

@alexellis

alexellis/app.go Secret

Created Feb 27, 2017
Embed
What would you like to do?
package main
import (
"fmt"
"net/http"
)
func main() {
myURL := "http://www.jonathanmh.com"
nextURL := myURL
var i int
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
for i < 100 {
resp, err := client.Get(nextURL)
if err != nil {
fmt.Println(err)
}
fmt.Println("StatusCode:", resp.StatusCode)
fmt.Println(resp.Request.URL)
if resp.StatusCode == 200 {
fmt.Println("Done!")
break
} else {
nextURL = resp.Header.Get("Location")
}
}
}
@willf
Copy link

willf commented Jun 6, 2017

You never increment the counter. I'd suggest i += 1 along with the nextUrl reassignment (line 32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment