在通过邮递员请求时,服务器端不提供http请求中带有下划线的标头参数

问题描述 投票:6回答:1

以下是API调用的curl导出失败 -

curl -X GET \
  'http://endpoint.in/dummy/path?mobile=777777777' \
  -H 'Content-Type: application/json' \
  -H 'auth_token: iubsaicbsaicbasiucbsa'

头文件param auth_token在服务器端根本不可用,从日志中检查。

然而,当直接作为命令发出时,相同的卷曲也起作用。我安装了最新的postman版本v6.2.3。此外,当通过Advanced REST client of chrome等其他工具请求时,相同的API端点也可以工作。

以前,我也检查了这个线程http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

许多服务器(如nginx)都有一个配置,如果设置,则丢弃名称中带下划线的标头。

但是,我无法验证相同,因为我无法确切地知道服务器是如何部署的。它是一个节点应用程序,我们运行此命令来运行应用程序 -

nohup /bin/forever start -o logs/out.log -e logs/err.log app.js

ps -ef | grep node显示以下内容 -

root      5981     1  0 Jul19 ?        00:00:00 /root/.nvm/v7.2.1/bin/node /usr/lib/node_modules/forever/bin/monitor app.js
root      5991  5981  0 Jul19 ?        00:00:04 /root/.nvm/v7.2.1/bin/node /usr/local/another/path/to/app.js

更新

这也通过Jmeter干扰了我们的自动化测试。

更新

我们在服务器上运行nginx,它似乎在调用节点进程。我们观察到在服务器上工作正常,nginx配置文件有这个设置 -

underscores_in_headers on;

但是这不存在于服务器的配置文件中。

另一个观察 - 我正在使用最新的邮递员版本 - 6.2.5,问题在那里。然而,当我把相同的邮差收集发送给另一个队友并且他在安装邮差之后点击它时,它对他有效。我仍然不确定问题是与邮递员还是服务器设置有关。

node.js http-headers postman
1个回答
1
投票

标题中未明确禁止下划线,但过去CGI下划线已转换为短划线。由于这种传统的NGINX和Apache HTTPD将标题中的下划线视为可能存在问题。

https://stackoverflow.com/a/22856867/2955337

您可以显式设置underscores_in_headers on;,但默认设置为off,因此默认情况下NGINX不接受下划线

http://nginx.org/en/docs/http/ngx_http_core_module.html#underscores_in_headers

curl显然将下划线转换成破折号来规避这个问题。

https://github.com/requests/requests/issues/1292#issuecomment-15997612

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.