node.js - 带有 https 目标的 Http 代理
问题描述
我正在尝试使用库在 NodeJs 中创建自己的代理服务器,node-http-proxy
问题是我想创建一个 http 代理服务器,它可以将请求转发到 https 目标(例如https://google.com)。
我知道这是可能的,因为已经有一个库可以做到这一点:proxy-chain
当我尝试使用以下命令请求 https 目标时,node-http-proxy
出现错误:ERR_EMPTY_RESPONSE
.
它还在文档中声明我需要添加 PKCS12 客户端证书,但proxy-chain
不这样做。
有没有办法可以proxy-chain
用图书馆复制node-http-proxy
图书馆?
这是我目前的代码:
var proxy = httpProxy.createProxyServer({});
var server = http.createServer(function(req, res) {
// You can define here your custom logic to handle the request
// and then proxy the request.
proxy.web(req, res, {
target: {
hostname: 'github.com',
port: 433,
protocol: 'https',
},
secure: false,
changeOrigin: true
});
});
console.log("listening on port 5050")
server.listen(5050);
解决方案
推荐阅读
- java - com.mysql.cj.jdbc.exceptions.MysqlDataTruncation:数据截断:日期值不正确:
- python - 使用 USDA Food API 按食品名称而不是 foodID 进行搜索
- c++ - *New Coder* 格式化和操作符
- excel - 格式化表格样式“”,接收变量未定义错误码
- c# - Visual Studio 2019 类图设计器工具箱为空
- sql - 在 SQL Server 2016 中将日期从 T 格式转换为 YYYYMMDD 格式
- swift - 如何在 SwiftUI 中将滚动视图添加到屏幕的特定部分?
- python - 我不知道 Flask 中的 SQLAlchemy 缺少哪些库
- javascript - 元素隐式具有“任何”类型,因为“字符串”类型的表达式不能用于索引类型 - Phaser
- vpn - 直接在C中而不是通过Swift中的packetFlow.readPackets读取tun FD时,如何处理tun FD数据包的前导4字节协议?