1 Star 1 Fork 1

kuaidaili/node.js-sdk

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
http_tls_util.js 1.44 KB
一键复制 编辑 原始数据 按行查看 历史
Eminem 提交于 4年前 . update examples
let http = require('http'); // 引入内置http模块
let tls = require('tls'); // 引入内置tls模块
let util = require('util');
// 用户名密码认证(私密代理/独享代理)
const username = 'username';
const password = 'password';
const auth = 'Basic ' + new Buffer.from(username + ':' + password).toString('base64');
// 代理服务器ip和端口
let proxy_ip = '59.38.241.25';
let proxy_port = 23916;
// 要访问的主机和路径
let remote_host = 'https://dev.kdlapi.com/testproxy';
let remote_path = '/';
// 发起CONNECT请求
let req = http.request({
host: proxy_ip,
port: proxy_port,
method: 'CONNECT',
path: util.format('%s:443', remote_host),
headers: {
"Host": remote_host,
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3100.0 Safari/537.36",
"Proxy-Authorization": auth,
"Accept-Encoding": "gzip" // 使用gzip压缩让数据传输更快
}
});
req.on('connect', function (res, socket, head) {
// TLS握手
let tlsConnection = tls.connect({
host: remote_host,
socket: socket
}, function () {
// 发起GET请求
tlsConnection.write(util.format('GET %s HTTP/1.1\r\nHost: %s\r\n\r\n', remote_path, remote_host));
});
tlsConnection.on('data', function (data) {
// 输出响应结果(完整的响应报文串)
console.log(data.toString());
});
});
req.end();
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/kuaidaili/node.js-sdk.git
git@gitee.com:kuaidaili/node.js-sdk.git
kuaidaili
node.js-sdk
node.js-sdk
master

搜索帮助