我正在尝试使用本地的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模块。而且有效!
所以我将这个 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 文件中遍历它。我对玉完全陌生。我怎么能去做这件事?