我需要从具有NodeJ的代理服务器(IP地址和端口)获取协议(HTTP或HTTPS)。
我有一个Nodejs服务器应用程序。在任何Windows计算机上安装应用程序时,它应自动从计算机获取代理配置,并允许所有请求通过代理服务器。
我能够从Windows注册表中找到代理服务器Ip和端口(HKEY_USERS.DEFAULT \ Software \ Microsoft \ Windows \ CurrentVersion \ Internet设置),但是我不怎么从代理Ip和端口中识别协议。
为什么需要识别协议(Http或HTTPS)? 我正在使用https://www.npmjs.com/package/https-proxy-agent npm模块来创建代理以发出任何头和后请求。
示例:从https://www.npmjs.com/package/https-proxy-agent
复制var url = require('url');
var https = require('https');
var HttpsProxyAgent = require('https-proxy-agent');
// HTTP/HTTPS proxy to connect to
var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';
console.log('using proxy server %j', proxy);
// HTTPS endpoint for the proxy to connect to
var endpoint = process.argv[2] || 'https://graph.facebook.com/tootallnate';
console.log('attempting to GET %j', endpoint);
var options = url.parse(endpoint);
// create an instance of the `HttpsProxyAgent` class with the proxy server information
var agent = new HttpsProxyAgent(proxy);
options.agent = agent;
https.get(options, function (res) {
console.log('"response" event!', res.headers);
res.pipe(process.stdout);
});
下面这行期望包含代理信息的协议
// HTTP/HTTPS proxy to connect to
var proxy = process.env.http_proxy || 'http://168.63.76.32:3128';
我尝试过https://www.npmjs.com/package/check-proxy,但这不符合我的要求。
谢谢