Jac*_*son 8 javascript google-chrome unauthorized fetch redux
我最近从使用jQuery转向使用Redux的isomorphic-fetch.在IE中运行时,它设法获取正常.但是我在Chrome中运行时会得到以下内容.
Failed to load resource: the server responded with a status of 401 (Unauthorized)
Run Code Online (Sandbox Code Playgroud)
值得注意的是,web api确实启用了Windows身份验证.
这是执行fetch的代码:
export const fetchSearchResults = (name) => {
return (dispatch) => {
dispatch(requestSearchResults(name))
return fetch(API URI HERE)
.then(response => response.json())
.then(json => {
console.log('Fetch: ' + json.message.features.length)
dispatch(receiveSearchResults(json))
})
}
}
Run Code Online (Sandbox Code Playgroud)
Ale*_*tin 27
我想你在服务器上有基于cookie的身份验证.在这种情况下,它可能与credentials密钥有关fetch.在jQuery中使用的XHR请求总是发送你的cookie,但使用fetch你应该传递credentials选项
same-origin 如果您向同一来源(域)提出请求 include 除此以外像这样:
...
fetch(API_URI_HERE, {credentials: 'same-origin'})
...
Run Code Online (Sandbox Code Playgroud)
我认为它适用于IE,因为fetchpolyfill在引擎盖下使用XHR请求.
| 归档时间: |
|
| 查看次数: |
9240 次 |
| 最近记录: |