在Django中,很多东西都在request.META中,我当前的代码检查request.META中的HTTP_TOKEN之类的内容,所以在发送请求时我需要向该url发送请求,以便在接收服务器中出现数据在request.META。
我认为标题出现在那里,所以我尝试了这个:
python example:(I am sending request from javascript, but getting it work from any client is enough so I can implement finally using javascript).
r = requests.get(url, headers={'HTTP_TOKEN': 'abc'})
但是在收到请求之后,我在request.META中找不到类似HTTP_TOKEN的内容。
答案 0 :(得分:2)
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.
请参阅https://docs.djangoproject.com/en/dev/ref/request-response/
因此,在您的情况下,我认为您只需发送{"TOKEN": "abc"}
。