最新消息: 电脑我帮您提供丰富的电脑知识,编程学习,软件下载,win7系统下载。

获取连接ECONNREFUSED 127.0.0.1:80尝试HTTP请求时

IT培训 admin 4浏览 0评论

获取连接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检查您的网址。

发布评论

评论列表 (0)

  1. 暂无评论