PHP服务端允许跨域
加上需要允许跨域访问,配置如下(一下配置内容前不允许有其他任何输出操作):
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Origin: http://localhost:8080");
$origin = ['http://localhost:8080','http://localhost:8081'];
$AllowOrigin = 'http://localhost:8080';
if(in_array($_SERVER["HTTP_ORIGIN"],$origin)){
$AllowOrigin = $_SERVER["HTTP_ORIGIN"];
}
header("Access-Control-Allow-Origin: ".$AllowOrigin );
header("Access-Control-Allow-Methods: *");
header('Access-Control-Allow-Credentials:true');
header('Access-Control-Allow-Headers:token');
允许请求方法
header("Access-Control-Allow-Methods: GET, POST, PATCH, PUT, DELETE, OPTIONS");
设置语序携带cookie
header('Access-Control-Allow-Credentials:true');
设置允许请求头
header('Access-Control-Allow-Headers: Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since, X-CSRF-TOKEN, X-Requested-With');
|