2

在 Django 中,很多东西都存在于 request.META 中,我当前的代码会检查 request.META 中的 HTTP_TOKEN 之类的内容,因此在发送请求时,我需要向该 url 发送请求,以便在接收服务器中,数据出现在请求中。元。

我认为标题出现在那里,所以我尝试了这个:

  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 的东西。

4

1 回答 1

4

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"}.

于 2013-07-27T20:51:23.267 回答