2016-01-22 43 views
0

我試圖訪問遠程URL,只是其輸出,這個工程:當我嘗試訪問http.get響應時,爲什麼我的應用程序中斷?

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); 
    }); 
}); 

我得到一個Unable to load the webpage because the server sent no data.我也試過res.send(response)

我不確定我的設置,但是如果我編寫本地主機:80,我得到我正在嘗試登錄的頁面

+0

在瀏覽器的開發工具中檢查請求 - 服務器響應是什麼樣的? – CBroe

回答

0

原來,服務器是bre因爲我沒有輸出任何數據。我需要類似

res.render(); 
相關問題