Skip to content

Instantly share code, notes, and snippets.

@kkdai
Created January 27, 2020 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kkdai/abc4944f17d87fd68dda07388005c07a to your computer and use it in GitHub Desktop.
Save kkdai/abc4944f17d87fd68dda07388005c07a to your computer and use it in GitHub Desktop.
func HTTPwithCookies(url, ds_user_id, sessionid, csrftoken string) (b []byte, err error) {
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return
}
req.AddCookie(&http.Cookie{Name: "ds_user_id", Value: ds_user_id})
req.AddCookie(&http.Cookie{Name: "sessionid", Value: sessionid})
req.AddCookie(&http.Cookie{Name: "csrftoken", Value: csrftoken})
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
err = errors.New(url +
"\nresp.StatusCode: " + strconv.Itoa(resp.StatusCode))
return
}
return ioutil.ReadAll(resp.Body)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment