xmlHttpRequest from origin has been blocked by CORS policy:
时间: 2023-11-17 20:56:32 浏览: 148
cors-now:具有CORS标头的反向代理
这个错误一般是由于浏览器的同源策略引起的跨域问题。同源策略是浏览器的一种安全机制,它要求网页的源(包括协议、域名和端口)必须和请求的资源的源一致。当一个网页发起了跨域请求,浏览器会检查响应头中是否包含了"Access-Control-Allow-Origin"字段并且该字段的值与当前网页的源一致。如果不一致,浏览器就会拒绝这个请求,抛出类似于"Access to XMLHttpRequest at 'https://xx.cn' from origin 'http://localhost:8000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present"的错误。 [2]
解决这个问题的方法有多种,其中一种是在浏览器中添加一些参数来禁用安全策略,比如在Chrome浏览器中可以右键点击快捷方式,选择"属性",在目标字段的末尾添加"--disable-web-security --user-data-dir=D:\MyChromeDevUserData",然后重新启动浏览器。这种方法是最简单粗暴的解决方法,但是需要注意的是,这样做会降低浏览器的安全性,不建议在正式环境中使用。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *3* [Access to XMLHttpRequest at has been blocked by CORS policy: No ‘Access-Control-Allow-Origin‘ ...](https://blog.csdn.net/shidas/article/details/126039938)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
- *2* [Access to XMLHttpRequest at ‘xx‘ from origin ‘XXX‘ has been blocked by CORS policy: Cross origin...](https://blog.csdn.net/qq_40587195/article/details/127749122)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文