如何解决如何在Node JS中使用基本身份验证在Node-Fetch模块中传递数据
有人可以提供此代码帮助吗?当我通过一个具有基本身份验证状态的“发布”请求时,身份验证状态为200,但没有任何响应。在没有身份验证的情况下,相同的代码有效
let username = 'username';
let password = 'password';
let headers = new Headers();
headers.set('Authorization','Basic ' + base64.encode(username + ":" + password));
fetch('https://sandbox.transactions.com',{
method: 'post',body: JSON.stringify(body),headers: headers
})
.then(function(response) {
return response.json();
}).then(function(json) {
console.log(json);
}).catch(function(err) {
console.log('There is an error ');
res.status(500).send('There was an error while fetching');
});
解决方法
如果状态为200,则表示一切正常。如果没有得到任何数据作为回报,则可能意味着服务器没有适合您的数据。
来自page view:
除了对CONNECT的响应外,200响应始终具有有效负载,尽管原始服务器可以生成零长度的有效负载主体。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。