0
我正尝试使用请求模块调用外部API,当调用本地托管的API但在调用外部API时没有成功时,它正常工作。注:我身后代理这可能是问题使用请求模块在代理后面调用外部REST api
代码
app.get('/Get', function(req, res){
request.get('https://api.github.com/repos/request/request',
function(error, response, body) {
if (!error && response.statusCode === 200) {
res.send(response.body);}
else {
res.json(error);
}
});
});
app.listen(8080);
console.log("server is running at 8080");
它是否工作正常,如果我打电话给当地的API波纹管:
request.get('http://localhost:8080/hello',