如何在golang中从http请求中读取标头? [英] How can I read a header from an http request in golang?
本文介绍了如何在golang中从http请求中读取标头?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果收到类型为 http.Request
的请求,如何读取特定标头的值?在这种情况下,我想将jwt令牌的值从请求标头中拉出.
If I receive a request of type http.Request
, how can I read the value of a specific header? In this case I want to pull the value of a jwt token out of the request header.
推荐答案
您可以使用 r.Header.Get :
func yourHandler(w http.ResponseWriter, r *http.Request) {
ua := r.Header.Get("User-Agent")
...
}
这篇关于如何在golang中从http请求中读取标头?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文