我正在打印所有标题,我得到:
map[Cookie:[_ga=GA1.2.843429125.1462575405] User-Agent:[Mozilla/5.0
(Macintosh; Intel Mac OS X 10_11_3) AppleWebKit/601.4.4 (KHTML, like Gecko)
Version/9.0.3 Safari/601.4.4] Accept-Language:[en-us]
Accept-Encoding:[gzip, deflate] Connection:[keep-alive]
Accept:[text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8]]
这意味着我的浏览器正在发送“Cookie”、“User-Agent”、“Accept-Language”、“Accept-Encoding”、“Connection”和“Accept”,但没有“Host”值。
我怎样才能得到我的 https://en.wikipedia.org/wiki/Virtual_hosting在没有这个值的情况下工作?
最佳答案
它在 Golang http 文档中声明:
For incoming requests, the Host header is promoted to the Request.Host field and removed from the Header map.
这样就可以通过access获取host了
http.Request.Host
点击这里了解详情:https://golang.org/pkg/net/http/
关于http - 为什么我的 http 请求 header 字段中缺少主机?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37096166/