如何在http get请求中设置标头? [英] How to set headers in http get request?
本文介绍了如何在http get请求中设置标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在用 Go 做一个简单的 http GET:
I'm doing a simple http GET in Go:
client := &http.Client{}
req, _ := http.NewRequest("GET", url, nil)
res, _ := client.Do(req)
但我在 doc 中找不到自定义请求标头的方法,谢谢
But I can't found a way to customize the request header in the doc, thanks
推荐答案
Request 的 Header
字段是公开的.你可以这样做:
The Header
field of the Request is public. You may do this :
req.Header.Set("name", "value")
这篇关于如何在http get请求中设置标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文