2013-06-27 341 views
0

我想通過NodeJs上的Cntlm代理髮出HTTP請求,但我無法讓它工作。這是我的代碼:通過Cntlm代理的Http請求。

var http = require('http'); 

var options = { 
    host: 'http://127.0.0.1', 
    port: 3128, 
    path: "http://www.google.com", 
    headers: { 
    Host: "www.google.com" 
    } 
}; 

http.get(options, function(res) { 
    console.log("Got response: " + res.statusCode); 
}).on('error', function(e) { 
    console.log("Got error: " + e.stack); 
}); 

我總是得到以下錯誤:

Got error: Error: getaddrinfo ENOTFOUND 
at errnoException (dns.js:37:11) 
at Object.onanswer [as oncomplete] (dns.js:124:16) 

請幫助。

回答

0

我發現options.host不應該有協議('http://')。刪除,給我一個302 - 找到。只需將www.google.com更改爲非重定向網址即可獲得200-Ok。