在预检响应中,Access-Control-Allow-Methods不允许使用方法PUT

时间:2016-02-15 03:07:30

标签: angularjs apache cors

我一直在开发一个与PHP / Apache Web服务对话的Angular JS应用程序。

到目前为止它一直对POST和GET请求工作正常,但对于PUT我有以下错误

Method PUT is not allowed by Access-Control-Allow-Methods in preflight response.

我已经使用Postman测试了API,它运行得很好

有什么想法解决我的问题吗?感谢

请注意,API服务器Apache已经具有以下配置

Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Allow-Headers "Origin, X-Requested-With, Content-Type, Accept"
Header set Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS"
Options All
AllowOverride All
Allow from all

Chrome有此响应标题

HTTP/1.1 200 OK
Date: Mon, 15 Feb 2016 02:52:56 GMT
Server: Apache/2.4.7 (Ubuntu)
X-Powered-By: PHP/5.5.9-1ubuntu4.14
Allow: GET,HEAD,PUT,PATCH,DELETE
Cache-Control: no-cache
Set-Cookie: laravel_session=eyJpdiI6IldvM3Z5eUpKcUI5Q0RXam5UN283TEE9PSIsInZhbHVlIjoiV3FnTVpUcFliWjZvczFrM2VuYXpBamI5NmIwR24rdThPWGRuMUZjbjd5K0I2N3F1REp4ZFJVc3U3QnhCZmxmZ0ZONDU4SEVtWm42SUVEWmJhRmF6M1E9PSIsIm1hYyI6ImMzOTVlNDZhZmNjYWNlM2I1N2FjYjQ4N2FhZDc5ZWY2MWJhYTdiNDBlMWExMGJkYzczYzE1MTczMzAyYzVkMjEifQ%3D%3D; expires=Mon, 15-Feb-2016 04:52:56 GMT; Max-Age=7200; path=/; httponly
Access-Control-Allow-Origin: *
Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type,   Accept
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8

1 个答案:

答案 0 :(得分:8)

道歉,此事已经解决了一段时间了。这实际上是相当愚蠢的错误。如果我没有错,那是因为API方面存在参数错误

Chrome上的飞行前错误消息可能具有误导性

如果您有类似我的错误

,请检查您的变量