错误:Access-Control-Allow-Headers 不允许 Content-Type
当尝试发送 ajax 请求时,我在 Chrome 中收到此错误:
Content-Type is not allowed by Access-Control-Allow-Headers
在 Firefox 中一切正常。
谁能帮我解决这个问题?
I am getting this error in Chrome when trying to send an ajax request:
Content-Type is not allowed by Access-Control-Allow-Headers
Everything works fine in Firefox.
Can anyone help me to resolve this issue?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
我解决了向 Apache Web Server 虚拟主机配置添加以下设置的问题
I solved the problem adding to Apache Web Server virtual host configuration the following settings
PHP的解决方案:(
需要在任何其他内容之前发送)
Solution for PHP:
(Need to send that before any other content)
在node.js中设置CORS(跨站点HTTP请求)。对我来说,它看起来像下面这样:
Set up CORS (Cross-site HTTP Requests) in node. For me it looks like the following:
对于 nginx
参见
https://distinctplace.com/2017/04 /17/nginx-access-control-allow-origin-cors/
for nginx
see
https://distinctplace.com/2017/04/17/nginx-access-control-allow-origin-cors/
我遇到了同样的问题,我通过添加以下标头解决了它:
访问控制允许标头:内容类型
I had the same problem and I solved it by adding the following header:
Access-Control-Allow-Headers: content-type
对于使用 PHP 的我来说,即使我仅设置此标头设置,本地也可以工作:
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');
To me with PHP, localy works even if i set only this header setting:
header('Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept');