一般普通请求这样就可以
header("Access-Control-Allow-Origin: *"); // 指定允许的域名
header('Access-Control-Allow-Methods: *'); // 允许的 HTTP 方法
前端设置header设置"Content-Type": "application/json",”token":1111时:
header("Access-Control-Allow-Origin: *"); // 指定允许的域名
header('Access-Control-Allow-Methods: *'); // 允许的 HTTP 方法
header('Access-Control-Allow-Headers: x-requested-with, content-type,token');
以此类推
如果携带cookie是需要指定域名,
header("Access-Control-Allow-Origin: localhost:3000"); // 指定允许的域名
header('Access-Control-Allow-Methods: *'); // 允许的 HTTP 方法
header('Access-Control-Allow-Credentials: true'); // 允许携带认证信息
header('Access-Control-Allow-Headers: x-requested-with, content-type,token');