第一次遇到这个问题
错误代码:
Access to XMLHttpRequest at 'http://localhost:8081/public/getContent' from origin 'http://localhost:19601' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.
但是,我试过用同一个项目里面的其他app的接口测试,却可以正常返回数据,我的跨域配置应该没问题
tp5跨域配置:
header("Access-Control-Allow-Origin:*");
header("Access-Control-Allow-Methods:*");
header("Access-Control-Allow-Credentials",true);
header("Access-Control-Allow-Headers:DNT,X-Mx-ReqToken,Keep-Alive,User-Agent,X-Requested-With,X_Requested_With,If-Modified-Since,Cache-Control,Content-Type, Accept-Language, Origin, Accept-Encoding");
而且出现错误的app的接口中,需要参数的接口都会出现这个错误,不需要参数的是可以正常返回数据的
毫无头绪,各位路过的大佬指点一下
ps:国庆节快乐!
在路由或路由组调用
allowCrossDomain()
如果需要其他 header ,也一并调用。