我正在尝试访问谷歌云存储上存储桶中的文件。我已经为存储桶设置了 CORS 配置。但当我通过 https://发出请求时,出现此错误。它适用于通过 http://发出的请求。
“XMLHttpRequest 无法加载“FILENAME”。
预检响应中的 Access-Control-Allow-Headers 不允许请求 header 字段 X-Requested-With。”
最佳答案
您必须包含X-Requested-With
在 responseHeader
的值中您的配置中的成员:
[
{
"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 theAccess-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/