如何使用NodeJS Connect从请求中提取请求HTTP标头 [英] How to extract request http headers from a request using NodeJS connect

查看:442
本文介绍了如何使用NodeJS Connect从请求中提取请求HTTP标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获取使用Node JS的连接库包进行的请求的主机"标头.我的代码如下:

I'd like to get the "Host" header of a request made using Node JS's connect library bundle. My code looks like:

var app = connect()
  .use(connect.logger('dev'))
  .use(connect.static('public'))
  .use(function(req, res){

    var host = req.???

  })
 .listen(3000);

用于连接的文档在这里,但是在上面的代码中我看不到任何详细说明req对象的API的东西. http://www.senchalabs.org/connect/

The documentation for connect is here but I don't see anything detailing the API of the req object in the above code. http://www.senchalabs.org/connect/

编辑:请注意,成功的答案必须指向文档(我需要此文件来验证哪个版本提供了我要查找的API).

Edit: Note a successful answer must point to the documentation (I need this to verify which version provided the API I'm looking for).

推荐答案

如果使用Express 4.x,则可以按照

If you use Express 4.x, you can use the req.get(headerName) method as described in Express 4.x API Reference

这篇关于如何使用NodeJS Connect从请求中提取请求HTTP标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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