nodeJs 基本认证问题 [英] nodeJs basic authentication issue
本文介绍了nodeJs 基本认证问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在 nodejs (javascript) 中使用基本身份验证(用户名和密码)向外部 API 发出 API 请求时,我没有得到正确的响应
I'm getting no proper response while make an API request to external API using basic authentication (username and password) in nodejs (javascript)
我使用了下面的代码,响应是未定义",不确定这里缺少什么.但是我可以使用邮递员工具提出请求,没有任何问题.
I used the below code and the response is "undefined", not sure what is missing here. But I was able to make a request using postman tool without any issues.
const request = require('request')
const user = '*****';
const pass = '*****!';
const url = 'https://servicenow.com/api/table'
var options = {
url: url,
auth: {
username: user,
password: pass
}
};
request.get(options, (err, res, body) => {
if (err) {
return console.log(err);
}
console.log(body.url);
console.log(body.explanation);
});
回复:
undefined
undefined
推荐答案
如果你的 api 与 postman 正确,你可以根据照片做这样的事情
if your api right with postman you can do like this based on photo
发送
一个请求- 点击
code
- 选择
nodejs-请求
复制
这篇关于nodeJs 基本认证问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文