UnityWebGL跨域问题

报错

Access to fetch at 'https://192.168.1.3:7777/' from origin 'https://192.168.1.3:8888' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

原因分析

由于浏览器的安全机制,要求访问Url同源,对于不同源的请求就会产生跨域的问题

解决方案

需要在被请求的服务器的返回消息中插入相应的请求头,以表示此消息支持跨域,具体做法如下:

在IIS,192.168.1.3:7777服务器中的HTTP响应头中添加如下图所示三条

或者直接在对应的web.config中添加

<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Methods" value="GET, POST, PUT, DELETE, OPTIONS" />
<add name="Access-Control-Allow-Headers" value="Content-Type" />
</customHeaders>
</httpProtocol>

引用

https://blog.csdn.net/qq_20991149/article/details/122433336

https://cloud.tencent.com/developer/article/1953193


已发布

分类

来自

标签:

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注