私は以下のコードを使用してAPIからデータを取得しています。私はセキュリティで保護された別のAPIを持っており、コンテンツにアクセスするにはユーザー名/パスワードが必要です。同形フェッチモジュールを使用する場合、資格情報を渡す方法がわかりません。助けてもらえますか?同形フェッチ(REDUX/nodeJs) - ユーザー名/パスワードによるPOSTリクエスト
私はこのモジュールを使用しています:https://www.npmjs.com/package/isomorphic-fetch
私は(サンプルcurlコマンド)以下のようにユーザー名とパスワードを渡す必要があり
curl -u admin:hello123 http://test:8765/select?q=*
コード:ほとんどのAPIを使用します
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){
});