这应该是非常简单的,但我没有得到数据,而是变得不确定。
我在代理服务器后面,我不擅长从代理服务器后面发出请求。我发现只有一个教程解释了在不使用外部模块的情况下使用代理服务器时的http请求,但没有正确解释。
const http = require('http');
let options = {
host: '10.7.0.1',
port:8080,
path:'www.google.co.uk'
}
http.get(options,(res) => {
let str = '';
res.setEncoding('utf8');
res.on('data', (chunk) => {
str += chunk;
})
res.on('end', (str) => {
console.log(str);
})
})
10.7.0.1是代理服务器的地址,8080是端口。
此代码的输出未定义。
我甚至不知道这个方法是否正确,我也不知道它是否正确。我阅读了节点http文档,并根据我的理解编写了options对象,如果我错了,请纠正我。
一般来说,当我在代理服务器后面时,我如何发出请求。
发布于 2018-06-25 03:05:11
request
包允许以一种非常优雅的方式发出http
请求,为了指定代理,只需将options对象请求中的proxy
键值设置为参数即可。
const request = require('request');
request({url: 'http://example.com', proxy: 'https://host:port'}, (error, response, body) => {
//Do whatever you want
});
https://stackoverflow.com/questions/46125250
复制相似问题