无法加载 XMLHttpRequest。在预检响应中 Access-Control-Allow-Headers 不允许请求 header 字段密码
XMLHttpRequest cannot load. Request header field password is not allowed by Access-Control-Allow-Headers in preflight response
我在执行 ajax 请求时收到以下错误消息
XMLHttpRequest cannot load. Request header field password is not allowed by Access-Control-Allow-Headers in preflight response.
我将以下内容用作 dojo 中的 header:
'Authorization': 'Bearer ' + this.data.token,
'X-Requested-With': null,
'If-None-Match': null,
'Password': this.data.oneTimePassword
下图来自 Chrome 的响应 Header。
我想知道:
您能否确认问题与 Access-Control-Allow-Headers
有关,其中不包含自定义 header password
?
如果端点应该只支持方法 GET,Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
在我的响应 Header 中是否正确,不应该只支持 Access-Control-Allow-Methods: GET
?
目前我正在使用 dojo/store/JsonRest
,但我认为问题与 API 有关,而不是道场本身。
"Is the problem related to Access-Control-Allow-Headers which does not contain custom header password?
是的。错误消息明确指出。
If the endpoint should support only method GET, is Access-Control-Allow-Methods correct in my API?
FSVO 正确。
它允许 GET,因此您可以发出 GET 请求。
它还允许其他方法,如果浏览器尝试使用其中一种方法发出请求,服务器可能会抛出 405。
我在执行 ajax 请求时收到以下错误消息
XMLHttpRequest cannot load. Request header field password is not allowed by Access-Control-Allow-Headers in preflight response.
我将以下内容用作 dojo 中的 header:
'Authorization': 'Bearer ' + this.data.token,
'X-Requested-With': null,
'If-None-Match': null,
'Password': this.data.oneTimePassword
下图来自 Chrome 的响应 Header。
我想知道:
您能否确认问题与
Access-Control-Allow-Headers
有关,其中不包含自定义 headerpassword
?如果端点应该只支持方法 GET,
Access-Control-Allow-Methods: GET, POST, PUT, OPTIONS
在我的响应 Header 中是否正确,不应该只支持Access-Control-Allow-Methods: GET
?
目前我正在使用 dojo/store/JsonRest
,但我认为问题与 API 有关,而不是道场本身。
"Is the problem related to Access-Control-Allow-Headers which does not contain custom header password?
是的。错误消息明确指出。
If the endpoint should support only method GET, is Access-Control-Allow-Methods correct in my API?
FSVO 正确。
它允许 GET,因此您可以发出 GET 请求。
它还允许其他方法,如果浏览器尝试使用其中一种方法发出请求,服务器可能会抛出 405。