xmlhttprequest - 请求头字段X-Requested

标签 xmlhttprequest cors google-cloud-platform google-cloud-storage preflight

我正在尝试访问谷歌云存储上存储桶中的文件。我已经为存储桶设置了 CORS 配置。但当我通过 https://发出请求时,出现此错误。它适用于通过 http://发出的请求。

“XMLHttpRequest 无法加载“FILENAME”。

预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段 X-Requested-With。”

最佳答案

您必须包含X-Requested-WithresponseHeader 的值中您的配置中的成员:

[
    {
      "origin": ["http://example.appspot.com"],
      "responseHeader": ["X-Requested-With"],
      "method": ["GET", "POST"],
      "maxAgeSeconds": 3600
    }
]

参见the relevant docs ,其中说:

If this is a preflight request, check if the preflight request includes one or more Access-Control-Request-Header. If so, then ensure that the matching CORS configuration entry includes a <ResponseHeader> entry for each requested header. All headers named in the Access-Control-Request-Header must be in the CORS configuration for the preflight request to succeed and include CORS headers in the response.

关于xmlhttprequest - 请求头字段X-Requested,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43420078/

相关文章:

javascript - 带有 Content-Disposition 的 HTTP 响应不会触发下载

javascript - LinkedIn OAuth 重定向登录返回 "No ' Access-Control-Allow-Origin' header is present on the requested resource“错误

cors - 在 NestJs 中,是否可以为各个路由启用 CORS?

javascript - 确定由于CORS问题导致的提取错误

python - 从数据流 (Python) 将嵌套架构写入 BigQuery

google-cloud-platform - Datalab 在 TreeView 中看不到符号链接(symbolic link)

java - 在 Google App Engine 上选择 Java 还是 Python

xmlhttprequest - 与 XHR-Polling、Socket.io 和 Titanium 频繁断开连接

javascript - XHR 请求的 CSRF 预防

javascript - 解析 JSON 后元素消失