I'm facing problem to get data from Django Headers.
My API using CURL:-
curl -X POST \
https://xyx.com \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/json' \
-H 'xyzId: 3223' \
-H 'abcData: ABC-123' \
-d '{
"name": "xyz",
"dob": "xyz",
"user_info": "xyz",
}'
In my API I need to get xyzId
and abcData
I tried request.META['abcData']
but got error KeyError
.
How do I get Both data in my view?
Please help me to out this problem.
Thanks in advance.
As per documentations say https://docs.djangoproject.com/en/2.0/ref/request-response/#django.http.HttpRequest.META
With the exception of CONTENT_LENGTH and CONTENT_TYPE, as given above, any HTTP headers in the request are converted to META keys by converting all characters to uppercase, replacing any hyphens with underscores and adding an HTTP_ prefix to the name. So, for example, a header called X-Bender would be mapped to the META key HTTP_X_BENDER.
So you should be able to access your header like this
request.META['HTTP_ABCDATA']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With