简体   繁体   English

已被 CORS 政策阻止:无“访问控制允许来源”

[英]has been blocked by CORS policy: No 'Access-Control-Allow-Origin'

I am trying to obtain data from a JSON, in local mode I can make it work, I have to enable a CORS extension in chrome and that's it.我正在尝试从 JSON 获取数据,在本地模式下我可以使其工作,我必须在 chrome 中启用 CORS 扩展,仅此而已。 Then when I have decided to upload the file to the server, on the server side with PHP, I enable the headers as follows然后,当我决定将文件上传到服务器时,在服务器端使用 PHP,我启用如下标头

<?php
header("Access-Control-Allow-Origin: *");
?>

y tambien en el .htaccess de la siguiente manera: y tambien en el .htaccess de la siguiente manera:

 <IfModule mod_headers.c>
   Header set Access-Control-Allow-Origin "*"
 </IfModule>

Access to XMLHttpRequest at 'https://www.siteExample.com/coins/151.json?hr=100' from origin 'https://meSiteExample.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

What else can I do?我还可以做些什么?

As I read here , Maybe you need use:正如我在这里读到的,也许你需要使用:

Header add Access-Control-Allow-Origin "*"

Instead of:代替:

Header set Access-Control-Allow-Origin "*"

in your .htaccess file.在您的 .htaccess 文件中。

Also Remember & pay attention '*' will enable CORS for all websites.另请记住并注意'*'将为所有网站启用 CORS。 and it has security risks.并且存在安全隐患。 if you know your request coming from where, you can filter that by enter domain instead of '*' .如果您知道您的请求来自哪里,您可以通过输入域而不是'*'来过滤它。
For example:例如:

Header add Access-Control-Allow-Origin "example.com" //OR "localhost"

use this instead of esterik * Access-Control-Allow-Headers: Accept用这个代替esterik * Access-Control-Allow-Headers: Accept

暂无
暂无

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

相关问题 访问 abcd.com 上的字体已被 CORS 政策阻止:没有“访问控制允许来源” - Access to Font at abcd.com has been blocked by CORS policy: No 'Access-Control-Allow-Origin' PHP-CORS策略已阻止对字体的访问:没有“ Access-Control-Allow-Origin”标头 - PHP - Access to Font has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header 无法在React中使用GraphQL查询-已被CORS策略阻止:所请求的资源上不存在“ Access-Control-Allow-Origin”标头 - Cannot use GraphQL queries in React - has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource 被 CORS 策略阻止:“Access-Control-Allow-Origin”header 包含多个值 - Blocked by CORS policy: The 'Access-Control-Allow-Origin' header contains multiple values Laravel7 CORS:被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:否 'Access-Control-Allow-Origin' - Laravel7 CORS : blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' Cors header “访问控制允许来源”被阻止 Api 响应 - Cors header “Access-control-allow-origin” blocked Api Response Laravel 从源访问 XMLHttpRequest 已被 CORS 策略阻止 - Laravel Access to XMLHttpRequest at from origin has been blocked by CORS policy Laravel Cors Access-Control-Allow-Origin - Laravel Cors Access-Control-Allow-Origin Laravel 上的 CORS (Access-Control-Allow-Origin) - CORS (Access-Control-Allow-Origin) on Laravel Codeigniter CORS 策略:没有“Access-Control-Allow-Origin”错误如何解决? - Codeigniter CORS policy: No 'Access-Control-Allow-Origin' error How to resolve?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM