php thinkphp 接口跨域问题 设置了headers 还是报错的解决方案 OPTIONS 跨域
Posted 空 的技术分享
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php thinkphp 接口跨域问题 设置了headers 还是报错的解决方案 OPTIONS 跨域相关的知识,希望对你有一定的参考价值。
if($_SERVER[‘REQUEST_METHOD‘] == ‘OPTIONS‘){
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
header(‘Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH‘);
exit;
}
//上面的代码很关键 问题就出在上面这里
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
header(‘Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH‘);
x
1
2
if($_SERVER[‘REQUEST_METHOD‘] == ‘OPTIONS‘){
3
header("Access-Control-Allow-Origin: *");
4
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
5
header(‘Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH‘);
6
exit;
7
}
8
//上面的代码很关键 问题就出在上面这里
9
header("Access-Control-Allow-Origin: *");
10
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
11
header(‘Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH‘);
以上是关于php thinkphp 接口跨域问题 设置了headers 还是报错的解决方案 OPTIONS 跨域的主要内容,如果未能解决你的问题,请参考以下文章