我正在尝试使用本机 node.js
http
模块向 news.google.com 发出 http 请求。我在尝试以下操作时收到connect ECONNREFUSED 127.0.0.1:80
错误
var http = require('http');
var payload = JSON.stringify({
name: 'John Smith',
email: 'john.smith@smith.com',
resume: 'https://drive.google.com/open?id=asgsaegsehsehseh'
});
var options = {
hostname: 'https://news.google.com',
path: '/',
method: 'GET'
};
var httpRequest = http.request(options, function(request, response) {
console.log('STATUS', response.statusCode);
response.setEncoding('utf8');
response.on('data', function(chunk) {
console.log('BODY:', chunk);
});
response.on('end', function() {
console.log('No more data in response');
});
});
httpRequest.on('error', function(e) {
console.log('Error with the request:', e.message);
});
httpRequest.write(payload);
httpRequest.end();
为什么我会收到此错误?
我尝试使用 request
npm 模块。它奏效了!
原文由 ng-hacker-319 发布,翻译遵循 CC BY-SA 4.0 许可协议
我对 jest 和 supertest 有同样的问题。刚刚将
api/blogs
更改为/api/blogs
并且有效!