我可以使用CORS成功地对我的服务进行GET调用。但是,在POST,PUT和DELETE的预检级别上肯定会出现问题。我在角度js上我已经尝试过将所有东西放在服务器端头上。就像
$app = \Slim\Slim::getInstance();
$res = $app->response();
// $origin=$app->request->headers->get("ORIGIN") ? $app->request->headers->get("ORIGIN"):'*';
// $origin = $app->request->getHeader("ORIGIN") ? $app->request->getHeader("ORIGIN") : '*';
$res->header('Content-Type', 'application/json');
$res->header('Access-Control-Allow-Origin','*');
// $res->header("Access-Control-Allow-Credentials: true");
$res->header('Access-Control-Allow-Headers', 'x-requested-with, content-type');
$res->header('Access-Control-Allow-Methods', 'GET, POST, PUT, DELETE');
$res->header('Access-Control-Max-Age: 86400');
$res->write(json_encode($response));
当我尝试使用跨域的post方法时,它会给我这样的错误
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8100' is therefore not allowed access.
任何帮助都会受到赞赏。只有函数正在编写交叉脚本为什么?
答案 0 :(得分:1)
您需要使用:
"Access-Control-Allow-Headers" -> "Origin, X-Requested-With, Content-Type, Accept".