Golang 发送http POST/GET请求时设置header
package main
import ("fmt""io/ioutil""net/http" "os""encoding/json"
)func main() { //生成client 参数为默认client := &http.Client{}//生成要访问的urlurl := "http://somesite/somepath/"//提交请求reqest, err := http.NewRequest("GET", url, nil)//增加header选项reqest.Header.Add("Cookie", "xxxxxx")reqest.Header.Add("User-Agent", "xxx")reqest.Header.Add("X-Requested-With", "xxxx")if err != nil {panic(err)} //处理返回结果response, _ := client.Do(reqest)defer response.Body.Close()