如何在http获取请求中设置标题? [英] How to set headers in http get request?

查看:107
本文介绍了如何在http获取请求中设置标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Go上做了一个简单的http GET:

  client:=& http.Client {} 
req,_:= http.NewRequest(GET,url,nil)
res,_:= client.Do(req)

但是我找不到一种方法来定制 doc ,谢谢

解决方案

Header 请求的字段是公开的。您可以这样做:

  req.Header.Set(name,value)


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

解决方案

The Header field of the Request is public. You may do this :

req.Header.Set("name", "value")

这篇关于如何在http获取请求中设置标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆