请求报头字段Content-Type不被Access-Control-Allow-Headers允许



所以我有我的开发服务器在d2.websta。我还有另一个url https://websta.me还有一些后端函数我想在d2。websta。me

中使用

我使用codeigniter为我的后端和angularjs前端

header('Access-Control-Allow-Headers: X-Requested-With,Origin,Accept');
header('Access-Control-Allow-Headers: Content-Type');
header('Access-Control-Allow-Headers: Authorization');
header('Content-Type: application/json; charset=utf-8');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Methods: GET, POST, PUT, DELETE');
header('Access-Control-Allow-Origin: https://websta.me');

我已经放了这么多的头,但我仍然得到错误的内容类型是不允许访问-控制-允许头..

我做错什么了吗?或者我必须编辑这些标题吗?或者我怎么解决这个问题?

from PHP side ->后端服务器标题("Access-Control-Allow-Origin: your-front-end-url-here");

from角侧

返回http({美元{'Content-Type': 'application/x-www-form-urlencoded'},url:"your-back-end-url-here",方法:"文章",数据:$参数})

应该

如果您试图从一个域向另一个域发送请求,您应该使用curl而不是像您在请求同一域时使用的常规请求。在你的例子中是两个不同的域。

Update:用于服务器-服务器请求。你能在这里张贴你的ajax代码吗?

我前面提到的方法实际上在两个不同的域之间工作。

我有我的前端位于在domain.com和后端在我的backenddomain.com发送和接收数据没有问题。对于从前端到后端API的调用,你不需要curl ->它不是两个服务器上的两个php脚本之间的连接。实际上,即使这样,curl也不是绝对必要的

相关内容

最新更新