Golang http.NewRequest

🕙2023-02-07
req, err := http.NewRequest(http.MethodGet, "http://baidu.com", nil)
    if err != nil {
        panic(err)
    }
    req.AddCookie(&http.Cookie{
        Name:   "ugs",
        Value:  "ugs",
        Domain: "baidu.com",
        Path:   "/",
    })
    r, err := http.DefaultClient.Do(req)
    bytes, err := ioutil.ReadAll(r.Body)

其中req.AddCookie可以有多个,如果需要加header:

req.Header.Add("content-type", "application/x-www-form-urlencoded")

Sitemap · Rss

津ICP备2021004480号-3