袜子代用剂
一个 SOCKS 代理服务器 http.Agent 执行 HTTP 和 HTTPS
本单元提供 http.Agent 连接到一个
指定 SOCKS 代理服务器,可用内置服务器 http
财务报告和审定财务报表 https 模块.
也可与 ws 模块以建立 WebSocket
通过 SOCKS 代理连接 。 参见下"例"部分.
实例
import https from 'https';
import { SocksProxyAgent } from 'socks-proxy-agent';
const agent = new SocksProxyAgent(
'socks://your-name%40gmail.com:[email protected]'
);
https.get('https://ipinfo.io', { agent }, (res) => {
console.log(res.headers);
res.pipe(process.stdout);
});
ws WebSocket 连接示例
import WebSocket from 'ws';
import { SocksProxyAgent } from 'socks-proxy-agent';
const agent = new SocksProxyAgent(
'socks://your-name%40gmail.com:[email protected]'
);
var socket = new WebSocket('ws://echo.websocket.events', { agent });
socket.on('open', function () {
console.log('"open" event!');
socket.send('hello world');
});
socket.on('message', function (data, flags) {
console.log('"message" event! %j %j', data, flags);
socket.close();
});