http - Golang: how to follow location with cookie -
in case response http request redirection (http code 302) cookie,
how can instruct go client follow new location cookie has been received?
in curl, can achieved setting client with:
cookiefile = "" autoreferer = 1 followlocation = 1
how can in go?
with go 1.1 can use net/http/cookiejar
that.
here working example:
package main import ( "golang.org/x/net/publicsuffix" "io/ioutil" "log" "net/http" "net/http/cookiejar" ) func main() { options := cookiejar.options{ publicsuffixlist: publicsuffix.list, } jar, err := cookiejar.new(&options) if err != nil { log.fatal(err) } client := http.client{jar: jar} resp, err := client.get("http://dubbelboer.com/302cookie.php") if err != nil { log.fatal(err) } data, err := ioutil.readall(resp.body) resp.body.close() if err != nil { log.fatal(err) } log.println(string(data)) }
Comments
Post a Comment