获取连接ECONNREFUSED 127.0.0.1:80尝试HTTP请求时
我试图让使用本机的node.js
http
模块HTTP请求到news.google。我收到connect ECONNREFUSED 127.0.0.1:80
错误,当我尝试以下
var http = require('http');
var payload = JSON.stringify({
name: 'John Smith',
email: '[email protected]',
resume: ''
});
var options = {
hostname: '',
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模块。和它的工作!
就我而言,问题其实是,我用HTTP客户端,axios
的默认行为。
默认情况下,爱可信重定向我们127.0.0.1:80
如果没有找到请求的URL或http
方法(GET / POST / PUT)。所以,更好,如果还使用axios
检查您的网址。
获取连接ECONNREFUSED 127.0.0.1:80尝试HTTP请求时
我试图让使用本机的node.js
http
模块HTTP请求到news.google。我收到connect ECONNREFUSED 127.0.0.1:80
错误,当我尝试以下
var http = require('http');
var payload = JSON.stringify({
name: 'John Smith',
email: '[email protected]',
resume: ''
});
var options = {
hostname: '',
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模块。和它的工作!
就我而言,问题其实是,我用HTTP客户端,axios
的默认行为。
默认情况下,爱可信重定向我们127.0.0.1:80
如果没有找到请求的URL或http
方法(GET / POST / PUT)。所以,更好,如果还使用axios
检查您的网址。