【发布时间】:2016-11-28 14:27:07
【问题描述】:
我正在使用以下代码从 API 取回数据,它工作正常。我有另一个受保护的 API,需要用户名/密码才能访问内容,我不确定在使用同构提取模块时如何传递凭据。有人可以帮忙吗?
我正在使用这个模块: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){
});
【问题讨论】:
标签: node.js post redux isomorphic-fetch-api