我想要获取使用Node JS的连接库包发出的请求的"Host“头。我的代码看起来像这样:
var app = connect()
.use(connect.logger('dev'))
.use(connect.static('public'))
.use(function(req, res){
var host = req.???
})
.listen(3000);
connect的文档在这里,但我在上面的代码中没有看到任何详细说明req
对象的API的内容。http://www.senchalabs.org/connect/
API :注意,一个成功的答案必须指向文档(我需要这个来验证哪个版本提供了我正在寻找的)。
发布于 2015-05-18 19:36:59
如果使用的是Express4.x,则可以使用Express 4.x API Reference中所述的req.get(headerName)
方法
发布于 2015-07-29 19:09:48
要查看HTTP请求头的列表,您可以使用:
console.log(JSON.stringify(req.headers));
返回JSON格式的列表。
{
"host":"localhost:8081",
"connection":"keep-alive",
"cache-control":"max-age=0",
"accept":"text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"upgrade-insecure-requests":"1",
"user-agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/44.0.2403.107 Safari/537.36",
"accept-encoding":"gzip, deflate, sdch",
"accept-language":"en-US,en;q=0.8,et;q=0.6"
}
发布于 2012-10-31 05:24:47
检查console.log(req)
或console.log(req.headers);
的输出
https://stackoverflow.com/questions/13147693
复制相似问题