【问题标题】:CORS error persists after setting correct headers设置正确的标头后,CORS 错误仍然存​​在
【发布时间】:2017-08-30 07:49:50
【问题描述】:

我得到一个:

“XMLHttpRequest 无法加载http://ec2*******.us-west-1.compute.amazonaws.com:8080/users/login。对预检请求的响应未通过访问控制检查:否'请求的资源上存在 Access-Control-Allow-Origin' 标头。因此,不允许访问 Origin 'http://www.*******.com'。"

我已经通过邮递员(端点)验证了标头设置为:

Access-Control-Allow-Credentials →true
Access-Control-Allow-Origin →*
Content-Length →0
Date →Tue, 04 Apr 2017 22:14:08 GMT

allowedHeaders →X-Requested-With, Content-Type, Accept, Origin
allowedMethods →OPTIONS, GET, PUT, POST, DELETE, HEAD
allowedOrigins →*

但是,此错误仍然存​​在。对于 GET 请求,此错误不会出现,但在 POST 中会出现。有什么想法吗?

【问题讨论】:

    标签: cors


    【解决方案1】:

    当您将 Access-Control-Allow-Credentials 设置为 true 时,您无法为 Access-Control-Allow-Origin 设置通配符 (*)。如果是这种情况,基本上请求将失败。

    要解决此问题,您必须指定特定来源,例如请求域名。更多信息here

    【讨论】:

      猜你喜欢
      • 2016-12-25
      • 2020-01-28
      • 2017-08-04
      • 2017-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-12-12
      • 2018-10-12
      相关资源
      最近更新 更多