是否可以在不连接到远程代理服务器的情况下实现 IdMappedPortTCP之类的东西?
我需要的是一种方法来编辑每个 HTTP 标头(例如更改每个请求的用户代理),用于从我的计算机发送的每个请求,而无需连接到远程服务器。b)如果可能的话,我还想在不需要像 proxifier 这样的第三方应用程序的情况下捕获 delphi 中的所有 http 流量。
到目前为止我尝试过的是:
a) IdMappedPortTCP 然后绑定到远程代理服务器,然后我在 IdMappedPortTCPExecute 方法中修改每个请求中的 AThread.NetData。
b) 使用 proxifier 捕获计算机中的所有 http 流量。
到目前为止我尝试的是使用映射IdMappedPortTCP
到本地代理服务器(例如,,,,squid
),delegate
创建我自己的代理服务器(使用) - 所有这些都适用于 HTTP 连接,但需要安装根证书来修改 HTTPS 请求,即不受欢迎的。如果可以在无需安装根证书的情况下实现任何本地代理,那就太棒了!fiddler
ccproxy
indy 10
我也尝试过修改TCP REDIRECTOR CODE,但是在编程方面是新鲜的,我没有成功。我想我可以改变
procedure TForm1.IdTCPServer1Execute(AThread: TIdPeerThread);
var
Cli: TIdTCPClient;
Len: Cardinal;
Data: string;
begin
try
Cli := nil;
try
{ Create & Connect to Server }
Cli := TIdTCPClient.Create(nil);
Cli.Host := 'www.borland.com';
Cli.Port := 80;
{ Connect to the remote server }
Cli.Connect;
..............
这样我将从请求中提取主机和端口,然后cli.host
为每个请求动态分配给该主机和端口。我不知道这有多可行。像,它会因为连接到太多的远程主机而导致计算机挂起吗?
更新:使用TIdMappedPortTCP
,我AThread.Connection.Capture(myheaders,'');
现在可以将我的主机分配给myheaders.Values['host']
,如果AThread.Connection.ReadLn = 'CONNECT'
我将端口设置为 443,否则我将其设置为 80。我在正确的轨道上吗?
procedure TForm1.IdMappedPortTCP1Connect(AThread: TIdMappedPortThread);
var
myheaders: TIdHeaderList;
method : string;
begin
myheaders:=TIdHeaderList.Create;
try
method:= AThread.Connection.ReadLn;
Athread.Connection.Capture(myheaders);
if myheaders.Count<>0 then begin
if Pos('CONNECT',method)<>0 then begin
with TIdTCPClient(AThread.OutboundClient) do begin
Host:=myheaders.Values['host'];
Port:=443;
end;
end else begin
with TIdTCPClient(AThread.OutboundClient) do begin
Host:=myheaders.Values['host'];
Port:=80;
end;
end;
TIdMappedPortThread(AThread).NetData:= method + #13#10 + myheaders.Text + #13#10 + #13#10;
end else begin
TIdMappedPortThread(AThread).NetData:= method + #13#10 + #13#10;
outs.Lines.Add(TIdMappedPortThread(AThread).NetData);
end;
finally
myheaders.Free;
end;
end;
我已将该代码放在 OnConnect 事件中,但它似乎不起作用。我做错了什么?