CORS 请求的资源上不存在“Access-Control-Allow-Origin”标头
Posted
技术标签:
【中文标题】CORS 请求的资源上不存在“Access-Control-Allow-Origin”标头【英文标题】:CORS No 'Access-Control-Allow-Origin' header is present on the requested resource 【发布时间】:2014-07-06 12:10:17 【问题描述】:我收到以下错误:
XMLHttpRequest cannot load http://localhost:62574/ServiceClass.asmx?op=loadMarkersViaWebService. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:15540' is therefore not allowed access.
所以我在 Web.Config 中添加了以下内容,但是错误仍然存在:
<system.webServer>
<validation validateIntegratedModeConfiguration="false"/>
<modules runAllManagedModulesForAllRequests="true"/>
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="http://localhost:15540/"/>
</customHeaders>
</httpProtocol>
【问题讨论】:
我看到端口不匹配? @Niels 否,应用程序使用 15540,而 Web 服务使用 62574 在这里查看我接受的答案:***.com/questions/22127442/… @rikket ,找到解决方案了吗?我有同样的问题。 【参考方案1】:尝试使用这个..
<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
<add name="Access-Control-Allow-Headers" value="Content-Type, Accept" />
</customHeaders>
</httpProtocol>
【讨论】:
以上是关于CORS 请求的资源上不存在“Access-Control-Allow-Origin”标头的主要内容,如果未能解决你的问题,请参考以下文章
Axios 请求已被 cors 阻止,请求的资源上不存在“Access-Control-Allow-Origin”标头
问题Cors:请求的资源上不存在“Access-Control-Allow-Origin”标头[关闭]
获取“被 CORS 策略阻止:请求的资源上不存在 'Access-Control-Allow-Origin' 标头。”使用 Axios 使用 MERN 堆栈
CORS 问题 - 请求的资源上不存在“Access-Control-Allow-Origin”标头