[LayaAir 2.0]部署web后无法请求访问HTTP API接口数据,调试模式下可以访问获取
Access to XMLHttpRequest at 'http://192.168.3.70:8081/api/test?data=test' from origin 'http://192.168.3.70:8082' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
4 个回复
Sylar
赞同来自:
//初始化
_config = new HttpSelfHostConfiguration(url);
//API路由
_config.Routes.MapHttpRoute(
"API Default",
"api/{controller}/{username}",
new { username = RouteParameter.Optional });
//这是重点,从配置文件的appsettings节点中读取跨域的地址
var cors = new EnableCorsAttribute("*", "*", "*");
_config.EnableCors(cors);
熊猫大侠
赞同来自:
熊猫大侠
赞同来自:
Laya_XS
赞同来自: