简体   繁体   中英

What is the correct format to get Django Header value when Header name contain `_` underscore

My CURL command:-

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']

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.

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.

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.

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 )

underscores_in_headers on;

For Apache ( link )

SetEnvIfNoCase ^client.cdata$ ^(.*)$ fix_client_cdata=$1
RequestHeader set client-cdata %{fix_client_cdata}e env=fix_client_cdata

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM