Node.js 当我尝试访问http.get响应时,为什么我的应用程序会中断?
我正在尝试访问一个远程url并将其输出,这样可以:Node.js 当我尝试访问http.get响应时,为什么我的应用程序会中断?,node.js,express,Node.js,Express,我正在尝试访问一个远程url并将其输出,这样可以: app.get('/', function (req, res) { http.get({ hostname: 'localhost', port: 80, path: '/', agent: false // create a new agent just for this one request }, (response) => { co
app.get('/', function (req, res) {
http.get({
hostname: 'localhost',
port: 80,
path: '/',
agent: false // create a new agent just for this one request
}, (response) => {
console.log('foo');
});
});
但当我这样做的时候:
app.get('/', function (req, res) {
http.get({
hostname: 'localhost',
port: 80,
path: '/',
agent: false // create a new agent just for this one request
}, (response) => {
console.log(response);
});
});
我收到一个无法加载网页,因为服务器没有发送数据。
我还尝试了res.send(response)
我不确定我的设置,但是如果我写localhost:80,我会得到我试图记录的页面,结果是,服务器坏了,因为我没有输出任何数据。我需要做点什么
res.render();
在浏览器的开发工具中检查请求–服务器响应是什么样子的?