简体   繁体   English

如何解决“ CORS策略:“ Access-Control-Allow-Origin”标头的值不等于提供的来源。”

[英]How to solve "CORS policy: The 'Access-Control-Allow-Origin' header has a value that is not equal to the supplied origin.'?

I am working on an ionic 3 Project. 我正在做一个离子3项目。 When i run the project on android i get the following error. 当我在android上运行项目时,出现以下错误。

Access to XMLHttpRequest at 'https://baseurl.com/api' from origin 'file://' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: The 'Access-Control-Allow-Origin' header has a value 'https://baseurl.com' that is not equal to the supplied origin.

I started getting this error from last week monday and until then it was working fine. 从上周星期一开始,我开始收到此错误,直到此为止一切正常。

In the requests(POST/GET) i am using the following headers 在请求(POST / GET)中,我正在使用以下标头

headers.append('Content-Type', 'application/x-www-form-urlencoded');

or 要么

headers.append('Content-Type', 'application/json');

According to the ionic documentation CORS Errors , what i understood was that there are changes has to be done from the server side. 根据离子文档CORS错误 ,我了解到必须从服务器端进行更改。 Is there anything can be done from the ionic side? 从离子方面有什么可以做的吗? What could be the issue? 可能是什么问题?

Two problems with your issue. 您的问题有两个问题。 One is more simple, and one is that https://baseurl/api doesn't have a .com, or a .anything, so it is mostly invalid. 一种更为简单,一种是https://baseurl/api没有.com或.anything,因此它基本上是无效的。 The second that CORS is a necessary evil to deal with. 第二个问题是CORS是必须处理的罪恶。 You are going to have to set up a local server do deal with it, as some requests cannot be made by items being served by a file:// protocol. 您将不得不设置一个本地服务器来处理它,因为file://协议所服务的项目无法发出某些请求。 Local servers can be set up a variety of ways, depending on your situation. 可以根据您的情况以多种方式设置本地服务器。 It would be helpful to explain how you are running it, and what tools you are using, so that we may be able to better help you. 解释您的运行方式以及使用的工具将非常有帮助,以便我们可以更好地为您提供帮助。

The issue is due to a chrome update and for further details about the issue please refer This . 该问题是由于chrome更新造成的,有关此问题的更多详细信息,请参阅This

Update the 'Android System Webview' in google play store to the latest version and this issue will go away 将Google Play商店中的“ Android系统Webview”更新到最新版本,此问题将消失

暂无
暂无

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

相关问题 ionic:请求的资源上不存在“ Access-Control-Allow-Origin”标头 - ionic: No 'Access-Control-Allow-Origin' header is present on the requested resource WebView不存在“ Access-Control-Allow-Origin”标头[ANDROID] - WebView No 'Access-Control-Allow-Origin' header is present [ANDROID] 科尔多瓦没有访问控制允许来源 - cordova No Access-Control-Allow-Origin android webview - 访问控制允许来源 - android webview - Access-Control-Allow-Origin Angular 无“访问控制允许来源” - Angular No 'Access-Control-Allow-Origin' IONIC CORS 的噩梦……签名的 APK 仍然需要“Access-Control-Allow-Origin”才能运行 - IONIC CORS nightmare... Signed APKs still needs "Access-Control-Allow-Origin" to run JSON_2_Region.json。 所请求的资源上没有“ Access-Control-Allow-Origin”标头。 因此,不允许访问原始“空”。 - JSON_2_Region.json. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. 模型查看器颤动请求的资源上不存在“Access-Control-Allow-Origin”标头 - modelviewer flutter No 'Access-Control-Allow-Origin' header is present on the requested resource Android WebView“请求的资源上不存在'Access-Control-Allow-Origin'标头” - Android WebView “No 'Access-Control-Allow-Origin' header is present on the requested resource” Google Cast:加载元数据错误并且不存在Access-Control-Allow-Origin标头 - Google Cast: Load Metadata Error and No Access-Control-Allow-Origin header is present
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM