先来看一下问题
请求头有多余的参数
解决方案是配置允许
详细代码如下:
// 可跨域域名列表
$domains = [
'http://localhost:8080',
'http://test.qqqqq.cn',
];
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
if (in_array($origin, $domains)) {
header('Access-Control-Allow-Origin:' . $origin);
}
// 允许的请求头信息
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization");
//在请求头里加上需要允许的 header("Access-Control-Allow-Headers: Origin, 名称);
// 允许的请求类型
header('Access-Control-Allow-Methods: GET, POST, PUT,DELETE,OPTIONS,PATCH');
// 允许携带证书式访问(携带cookie)
header('Access-Control-Allow-Credentials:true');