header('Access-Control-Allow-Origin:*');不允许CORS请求 [英] header('Access-Control-Allow-Origin: *'); Not allowing CORS request

查看:86
本文介绍了header('Access-Control-Allow-Origin:*');不允许CORS请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个生成JSON文档的PHP文件.

I have a PHP file which generates a JSON document.

我已经按照以下步骤设置了 header ,但是仍然出现错误.

I've set the header as follows but am still getting an error.

header('Access-Control-Allow-Origin: *');
header('Content-Type: application/json');

错误消息:

所请求的资源上不存在"Access-Control-Allow-Origin"标头.因此,不允许访问来源"https://mysubdomain.mydomain.com".

我已经尝试过明确允许使用mysubdomain.mydomain.com

I've tried explictly allowing mysubdomain.mydomain.com using

header('Access-Control-Allow-Origin: https://mysubdomain.mydomain.com');

但是我仍然会收到错误消息.

But I still get the error.

推荐答案

设置标头的代码看起来没有什么问题,但是您可能要检查是否真的设置了标头.使用 curl -i http://yourapp 来检查正在发送的响应标头以对其进行调试.或者,您可以使用Google Chrome浏览器的网络检查器中的网络"标签,也可以使用Firefox的Web开发器工具中的网络"工具.

It doesn't look there is anything wrong with the code that sets the header, but you may want to check if the header is actually being set. Use curl -i http://yourapp to check the response headers being sent to debug it. Alternatively, you can use the network tab in Google Chrome's web inspector, or the Network tool in Firefox's Web Developer tools.

这篇关于header('Access-Control-Allow-Origin:*');不允许CORS请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆