1
我正在使用下面的代码从API获取数据并且工作正常。我有另一个安全的API,它需要用户名/密码才能访问内容,我不确定如何在使用同构提取模块时传递凭证。有人可以帮忙吗?同构提取(REDUX/nodeJs) - 带用户名/密码的POST请求
我使用这个模块:https://www.npmjs.com/package/isomorphic-fetch
我需要的用户名和密码,通过如下(样本curl命令)
curl -u admin:hello123 http://test:8765/select?q=*
代码:
fetch(
url
).then(function (response) {
if (response.status != 200) {
dispatch(setError(response.status + '===>' + response.statusText + '===>' + response.url))
}
return response.json();
}).then(function (json) {
dispatch(setData(json, q))
}).catch(function(err){
});