【问题标题】:Fetch request failing due to CORS missing token in Firefox由于 Firefox 中的 CORS 缺少令牌,获取请求失败
【发布时间】:2019-11-02 10:01:30
【问题描述】:

当尝试在 firefox 中发出 POST 请求时,出现以下错误消息:

跨域请求被阻止:同源策略不允许读取位于https://example.net/graphql 的远程资源。 (原因:CORS 预检通道的 CORS 标头“Access-Control-Allow-Headers”中缺少令牌“content-type”)。

跨域请求被阻止:同源策略不允许读取位于https://example.net/graphql 的远程资源。 (原因:CORS 请求未成功)。

相同的请求在 Chrome 中成功。我发送的请求是:

method: 'POST',
  headers:{
    'x-client-id': '123',
    'content-type': 'application/json; charset=UTF-8'
  },
  body: JSON.stringify({
    query: "query ..."
  })
})
.then(res => res.json())
.then(console.log);```

I am issuing this request while on another https origin.

My setup in my code for cors is simply the spring annotation:
```@CrossOrigin(allowedHeaders = {"content-type", "x-client-id"})```

【问题讨论】:

  • 尝试为该站点清除 Firefox 浏览器缓存,或强制重新加载

标签: java spring cors


【解决方案1】:

您将需要这些标题:

访问控制允许来源:http://api.bob.com

访问控制允许方法:GET、POST、PUT

Access-Control-Allow-Headers: X-Custom-Header Content-Type: text/html;

charset=utf-8

在目标上以允许 CORS。如果您无法访问远程内容,则使用您的服务器作为代理并从那里发送请求,将响应返回到您的浏览器。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-03-20
    • 2011-08-01
    • 1970-01-01
    • 2019-07-06
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多