Nodejs 表达请求标头 - 获取引用者等。

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15827891/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:07:16  来源:igfitidea点击:

Nodejs express request headers - get the referrer, etc.

node.jsexpress

提问by Harry

I get a post form a payment gateway https to verify a payment etc. I need to verify that the post was infact from the domain.

我收到一个来自支付网关 https 的帖子以验证付款等。我需要验证该帖子是否来自域。

Im trying to verify that the referrer is from a certain list of domains but in my req.headers I dont see a referrer|referer options:

我试图验证引用者是否来自某个域列表,但在我的 req.headers 中我没有看到引用者|引用者选项:

{ 'x-real-ip': '123.34.45.176',
  'x-forwarded-for': '123.34.45.176',
  host: 'my.foo.com',
  'x-nginx-proxy': 'true',
  connection: 'close',
  'user-agent': 'Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)',
  accept: '*/*',
  'content-length': '441',
  'content-type': 'application/x-www-form-urlencoded' }

Why is my headers empty of those fields such as referer, origin etc ?

为什么我的标题中没有引用者、来源等字段?

This is inside a post:

这是一个帖子里面:

app.post('/payment/notify/', function(req, res){
   req.headers
})

回答by Daniel

Not all requests have a referer header.

并非所有请求都有引用标头。

If the last page a browser was on is a secure server (https) then it does not transmit a referer to you.

如果浏览器所在的最后一页是安全服务器 (https),​​则它不会向您传输引用。

Also, if your user types your address into their address bar you don't get a referer as well.

此外,如果您的用户在他们的地址栏中键入您的地址,您也不会获得推荐人。