我正在尝试使用用编写的REST。
Get & Post方法的工作没有任何问题。但是删除请求不起作用。I get“访问控制-允许-方法不允许删除方法”
我已经允许选项以及删除标题。请参阅下面的代码。
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Methods: GET, PUT, POST, DELETE, OPTIONS');
$app->options('/(:name+)', function() use($app) {
$response = $app->response();
$app->response()->status(200);
$response->header('Access-Control-Allow-Origin', '*');
$response->header('Access-Control-Allow-Headers', 'Content-Type, X-Requested-With, X-authentication, X-client');
$response->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE, OPTIONS');
});这个请求失败的原因是什么?
发布于 2013-11-25 13:49:12
当前版本的Nginx (1.0.x)似乎不支持HTTP选项请求。当发送此请求时,它返回405“不允许的方法”。我在nginx服务器的配置文件中添加了标题,这解决了我的问题。
location / {
alias /usr/share/nginx/webapp/;
try_files $uri $uri/ /index.php;
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Allow-Headers' 'DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type';
add_header 'Access-Control-Allow-Methods' "GET, POST, OPTIONS, DELETE";
add_header 'Access-Control-Max-Age' 1728000;
return 200;
}
}--
https://stackoverflow.com/questions/20144847
复制相似问题