go - Wikipedia url stopped after 10 redirects error GoLang -


upon executing http request, receive following error:

2015/08/30 16:42:09 https://en.wikipedia.org/wiki/list_of_s%26p_500_companies:  stopped after 10 redirects 

in following code:

package main  import (     "net/http"     "log" )  func main() {     response, err := http.get("https://en.wikipedia.org/wiki/list_of_s%26p_500_companies")     if err != nil {         log.fatal(err)     } } 

i know according documentation,

// issues specified url. if response 1 of // following redirect codes, follows redirect, // maximum of 10 redirects: // //    301 (moved permanently) //    302 (found) //    303 (see other) //    307 (temporary redirect) // // error returned if there many redirects or if there // http protocol error. non-2xx response doesn't cause // error. 

i hoping knows solution in case. seems rather odd simple url results in more ten redirects. makes me think there may more going on behind scenes.

thank you.

as others have pointed out, should first give thought why encountering many http redirects. go's default policy of stopping @ 10 redirects reasonable. more 10 redirects mean in redirect loop. caused outside code. induced network configuration, proxy servers between , website, etc.

that said, if need change default policy, not need resort editing net/http source suggested.

to change default handling of redirects need create client , set checkredirect.

for reference: http://golang.org/pkg/net/http/#client

// if checkredirect nil, client uses default policy, // stop after 10 consecutive requests. checkredirect func(req *request, via []*request) error 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -