+ -
当前位置:首页 → 问答吧 → idtcpserver怎么做HTTP转发

idtcpserver怎么做HTTP转发

时间:2011-12-14

来源:互联网

环境:DELPHI XE2 INDY10
目标:HTTP数据转发,把电脑A的hosts里加入192.168.0.2 www.csdn.net,然后在电脑B(IP192.168.0.2)上运行本程序,接收电脑A的请求,再通过网络把请求发给www.baidu.com的IP.最后,把返回数据再传给电脑A.

打算使用idtcpserver和idtcpclient.

原型大概写了,但具体使用上有问题.

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
  idc:tidtcpclient;
  Buffer,buffer2: TidBytes;
  i,j:integer;
begin
  memo1.lines.add(acontext.Binding.PeerIP);
  idc:=tidtcpclient.Create(nil);
  idc.Host:=11.22.33.44;//HTTP目标IP
  idc.Port:=80;
  idc.Connect;
  
  AContext.Connection.iohandler.ReadBytes(buffer,i);//先取得A要转发的数据

  idc.IOHandler.Write(buffer,i);//转发到目标
  
  idc.IOHandler.ReadBytes(buffer2,j);//取得返回数据

  AContext.Connection.iohandler.Write(buffer2,j);//传回给A
 
  acontext.Connection.Socket.Close;
  idc.Socket.Close;
  idc.Free;
end;


因为不知道具体方法,函数和参数都有错误,请帮忙完善.

作者: cglzyz   发布时间: 2011-12-14

你单个的在不做转发的情况下能直接取得网站的能返回?

作者: zhouxianqun   发布时间: 2011-12-15