使用 Fetch with Authorization Header 和 CORS
Using Fetch with Authorization Header and CORS
我正在尝试让我的请求进入在线游戏 API,但我似乎无法开始工作。我正在使用 Fetch API,一些请求需要 Authorization Bearer token,但请求从未通过授权发送 header.
我试过了
mode: 'no-cors',
credentials: 'include'
并且显然将授权放在 header 中,就像这样
header: { 'Authorization': 'Bearer TOKEN' }
但请求仍未获得授权。谁能指出我正确的方向?
编辑
这是我提出请求的方式
fetch(URL, {
credentials: 'include',
header: {
'Authorization': 'Bearer TOKEN'
}
})
Keys can be passed either via query parameter or HTTP header. Guildwars API
servers do not support preflighted CORS requests, so if your
application is running in the user's browser you'll need to use the
query parameter.
To pass via query parameter, include "?access_token=" in your
request.
键名应该是headers,不是header.
fetch(URL, {
credentials: 'include',
headers: {
'Authorization': 'Bearer TOKEN'
}
})
我正在尝试让我的请求进入在线游戏 API,但我似乎无法开始工作。我正在使用 Fetch API,一些请求需要 Authorization Bearer token,但请求从未通过授权发送 header.
我试过了
mode: 'no-cors',
credentials: 'include'
并且显然将授权放在 header 中,就像这样
header: { 'Authorization': 'Bearer TOKEN' }
但请求仍未获得授权。谁能指出我正确的方向?
编辑 这是我提出请求的方式
fetch(URL, {
credentials: 'include',
header: {
'Authorization': 'Bearer TOKEN'
}
})
Keys can be passed either via query parameter or HTTP header. Guildwars API servers do not support preflighted CORS requests, so if your application is running in the user's browser you'll need to use the query parameter.
To pass via query parameter, include "?access_token=" in your request.
键名应该是headers,不是header.
fetch(URL, {
credentials: 'include',
headers: {
'Authorization': 'Bearer TOKEN'
}
})