简体   繁体   English

使用假API时出现CORS错误怎么解决?

[英]How to solve CORS error when using fake API?

I am using fake api and getting this well known "No 'Access-Control-Allow-Origin' header is present on the requested resource."我正在使用假 api 并得到这个众所周知"No 'Access-Control-Allow-Origin' header is present on the requested resource." I watched videos and read articles related to this problem but they are showing the solution while they are using their own server (express) and api but I am using a third party API then how I would set headers for it?我观看了与此问题相关的视频并阅读了文章,但他们在使用自己的服务器(快递)和 api 时展示了解决方案,但我使用的是第三方 API 那么我将如何为其设置标题?

The errors:错误:

错误(尽管它如此受欢迎以至于已经看到它 LOL))

A temporary shortcut solution: You can use an extension for your browser to solve CORS error.临时快捷解决方案:您可以使用浏览器的扩展程序来解决 CORS 错误。 Allow CORS: Access-Control-Allow-Origin允许 CORS:访问控制允许来源在此处输入图像描述

If you are using google chrome, you can simply disable web security during your development:如果您使用的是 google chrome,您可以在开发过程中简单地禁用 web 安全性:

  1. Open cmd打开 cmd

  2. Go to chrome.exe installation dir ( C:\Program Files\Google\Chrome\Application is Default dir): Go 到 chrome.exe 安装目录( C:\Program Files\Google\Chrome\Application是默认目录):

    cd C:\Program Files\Google\Chrome\Application cd C:\Program Files\Google\Chrome\Application

  3. Open chrome.exe with --disable-web-security argument:使用 --disable-web-security 参数打开 chrome.exe:

    chrome.exe --disable-web-security chrome.exe --disable-web-security

在此处输入图像描述

You can find more info for other OS here您可以在此处找到有关其他操作系统的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM