如何在http获取请求中设置头文件?(How to set headers in http get request?)
我在做一个简单的http GET
client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) res, _ := client.Do(req)但是,我找不到一种在文档中自定义请求头的方法,谢谢
I'm doing a simple http GET in Go:
client := &http.Client{} req, _ := http.NewRequest("GET", url, nil) res, _ := client.Do(req)But I can't found a way to customize the request header in the doc, thanks
最满意答案
请求的Header字段是公开的。 你可以这样做:
req.Header.Set("name", "value")The Header field of the Request is public. You may do this :
req.Header.Set("name", "value")更多推荐
发布评论