Django breaks CORS PUT OPTIONS request

≡放荡痞女 提交于 2019-12-11 04:58:41

问题


I've set up a REST API on a django and requesting things via JavaScript AJAX with CORS enabled. It works fine until I try to use a PUT request. Because django cannot handle PUT, I am using django-piston's coerce_put_post method. The problem is, that the PUT request is handled successfully but the OPTIONS request fails with 405 METHOD NOT ALLOWED.

This is the Network log of the failing request.

  • Request URL : http://localhost
  • Request Method : OPTIONS
  • Status Code : 405 METHOD NOT ALLOWED

Request Headers

  • Accept : /
  • Accept-Encoding : gzip,deflate,sdch
  • Accept-Language : de,en-US;q=0.8,en;q=0.6
  • Access-Control-Request-Headers : accept, origin, content-type
  • Access-Control-Request-Method : PUT
  • Cache-Control : no-cache
  • Connection : keep-alive
  • Host : foo
  • Origin : http://localhost
  • Pragma : no-cache
  • Referer : http://localhost/bar
  • User-Agent : Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.95 Safari/537.36

Response Headers

  • Access-Control-Allow-Credentials : true
  • Access-Control-Allow-Headers : Content-Type, Pragma, Cache-Control
  • Access-Control-Allow-Methods : POST,GET,OPTIONS,PUT,DELETE
  • Access-Control-Allow-Origin : http://localhost
  • Allow : post,get,options,put,delete
  • Content-Type : text/html; charset=utf-8
  • Date : Fri, 09 Aug 2013 09:39:41 GMT
  • Server : WSGIServer/0.1 Python/2.7.4

As you can see, the OPTIONS is actually allowed in the CORS headers.

So why does it still fail?

来源:https://stackoverflow.com/questions/18144224/django-breaks-cors-put-options-request

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!