1

i am using django rest-framework for posting or getting a data from the client application. The client application is sending a custom header along with the request. How can i access that custom header value in rest api.

Custome-Header-Key: ASDQWERYHH #This is the custom header set from the client.

Please help

Thanks

1 Answer 1

3

You can use the request.META dictionary.

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 to get the header value in your example you could do:

request.META['HTTP_CUSTOM_HEADER_KEY']
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.