[英]What is the correct format to get Django Header value when Header name contain `_` underscore
My CURL command:- 我的CURL命令:
curl -X POST \
http://localhost:8000/sendData/ \
-H 'authorization: Token b67d31c42d98b3c97b28c737629dca63ef5043fc' \
-H 'cache-control: no-cache' \
-H 'client_cdata: virat' \
-H 'clientdata: sachin' \
-H 'content-type: multipart/form-data;' \
-H 'postman-token: ed70d17c-ecf6-66c7-619e-85eac7d62803' \
-F purchasID=23124212 \
-F purchaserAmount=4320'
I tried to get Header Data 我试图获取标题数据
using request.META['HTTP_CLIENTDATA']
使用request.META['HTTP_CLIENTDATA']
I got the value sachin
same as when i try to get request.META['HTTP_CLIENT_CDATA']
it not working, It's showing the *** KeyError
error. 我获得的sachin
值与尝试获取request.META['HTTP_CLIENT_CDATA']
时的值相同,它显示*** KeyError
错误。
What is the correct format to get Header value when header name contain _
? 标头名称包含_
时,获取标头值的正确格式是什么?
I can't change header data, Because of this API is called by another domain(It result provided by another site or server), I'm creating API end points. 我无法更改标头数据,因为此API是由另一个域调用的(结果由另一个站点或服务器提供),所以我正在创建API端点。
Thanks in advance. 提前致谢。
Working on the assumption that you're probably using either Nginx or Apache as a reverse proxy, headers containing underscores are dropped by these servers to avoid problems when mapping such headers to CGI variables. 在假设您可能使用Nginx或Apache作为反向代理的前提下,这些服务器会删除包含下划线的标头,以避免将此类标头映射到CGI变量时出现问题。
If you need to support underscores - which it sounds as though you do, because they're coming from a third party - then you have to enable support. 如果您需要支持下划线(听起来像您那样,因为您来自第三方),那么您必须启用支持。
For Nginx ( link ) 对于Nginx ( link )
underscores_in_headers on;
For Apache ( link ) 对于Apache ( link )
SetEnvIfNoCase ^client.cdata$ ^(.*)$ fix_client_cdata=$1
RequestHeader set client-cdata %{fix_client_cdata}e env=fix_client_cdata
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.