我向google的主页发出了一个简单的Http请求,但是没有记录在控制台中的数据,而是显示了这个错误
错误:连接ETIMEDOUT 172.217.26.163:80
此外,我试图向谷歌的提出请求,但也没有得到任何数据。
这是我的代码(谷歌主页版)
const http = require('http');
let req = http.request('http://www.google.co.uk', function(response){
console.log(response.statusCode);
response.pipe(process.stdout);
});
req.end();
我也在代理服务器后面,可能是因为代理服务器吗?如果是,我如何在node.js本身中设置代理服务器。我已经为国家预防机制这么做了。
发布于 2017-08-21 05:07:48
您应该传递指向传递给host
的options
中的代理的options
和port
变量。
var options = {
host: "proxypath",
port: 8080,
path: "http://www.google.co.uk",
headers: {
Host: "http://www.google.co.uk"
}
};
http.request(options, function(response) {
console.log(response.statusCode);
response.pipe(process.stdout);
});
https://stackoverflow.com/questions/45797399
复制相似问题