【问题描述】
Thinkphp6 开发的api接口,使用apipost等工具携带token可以正常访问,项目中携带token报错跨域访问
【解决方案】
在入口文件 index.php 中,增加一下代码
header("Access-Control-Allow-Origin: *");
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
header("Access-Control-Allow-Headers: *");
header("Access-Control-Allow-Methods: GET, POST, PUT, DELETE, OPTIONS, PATCH");
exit();
}