小编ng-*_*319的帖子

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

我正在尝试使用本地的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();
Run Code Online (Sandbox Code Playgroud)

为什么会出现此错误?

我尝试使用requestnpm模块。而且有效!

post get http request node.js

7
推荐指数
4
解决办法
2万
查看次数

如何使用 Jade 和 Node.js 遍历 JSON 数组

所以我将这个 JSON 数组apiData作为data.

后端

router.get('/', function(req, res) {
    var data = JSON.stringify(apiData);
    res.render('gallery', { data: apiData });
}); 
Run Code Online (Sandbox Code Playgroud)

前端

extends layout

block content
    h1 MyProject
    !{JSON.stringify(data)}
Run Code Online (Sandbox Code Playgroud)

我正在尝试缓存!{JSON.stringify(data)}一个变量并在 jade 文件中遍历它。我对玉完全陌生。我怎么能去做这件事?

javascript templates http node.js pug

2
推荐指数
1
解决办法
9830
查看次数

标签 统计

http ×2

node.js ×2

get ×1

javascript ×1

post ×1

pug ×1

request ×1

templates ×1