我正在尝试从我的项目中的外部URL获取一些数据(angular2服务器端)。我总是得到ETIMEDOUT错误。这是我的代码
var request = require('request');
var username = "username",
password = "pwd",
url = "myURL",
auth = "Basic " + new Buffer(username + ":" + password).toString("base64");
request(
{
method: 'GET',
url: url,
headers: {
"Authorization": auth
}
},
function (error, response, body) {
console.log('Error: '+error);
console.log('Response: '+response);
console.log('Body: '+body);
}
);