unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdSocks, IdIOHandler,
IdIOHandlerSocket, IdSSLOpenSSL, IdBaseComponent,
IdComponent, IdTCPConnection, IdTCPClient, IdHTTP, Gauges;
function Pars(T_, ForS, _T: string): string;
type
TForm1 = class(TForm)
// IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IdSocksInfo1: TIdSocksInfo;
Button1: TButton;
Edit1: TEdit;
Label1: TLabel;
Label2: TLabel;
ComboBox1: TComboBox;
Memo1: TMemo;
Gauge1: TGauge;
IdHTTP1: TIdHTTP;
IdSSLIOHandlerSocket1: TIdSSLIOHandlerSocket;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
procedure IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
procedure IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function Pars(T_, ForS, _T: string): string;
var
a, b: integer;
begin
Result := '';
if (T_ = '') or (ForS = '') or (_T = '') then
Exit;
a := Pos(T_, ForS);
if a = 0 then
Exit
else
a := a + Length(T_);
ForS := Copy(ForS, a, Length(ForS) - a + 1);
b := Pos(_T, ForS);
if b > 0 then
Result := Copy(ForS, 1, b - 1);
end;
procedure TForm1.Button1Click(Sender: TObject);
var Code:string;
begin
case ComboBox1.ItemIndex of
0: begin // HTTP
IdHTTP1.IOHandler:=nil;
IdHTTP1.ProxyParams.ProxyServer:=Copy(Edit1.Text,1,Pos(':',Edit1.Text)-1);
IdHTTP1.ProxyParams.ProxyPort:=StrToInt(Copy(Edit1.Text,Pos(':',Edit1.Text)+1,Length(Edit1.Text)));
end;
1: begin // SOCKS4
IdHTTP1.ProxyParams.ProxyServer:='';
IdHTTP1.ProxyParams.ProxyPort:=0;
IdSocksInfo1.Version:=svSocks4;
IdSocksInfo1.Host:=Copy(Edit1.Text,1,Pos(':',Edit1.Text)-1);
IdSocksInfo1.Port:=StrToInt(Copy(Edit1.Text,Pos(':',Edit1.Text)+1,Length(Edit1.Text)));
IdSocksInfo1.Authentication:= saNoAuthentication;
IdSSLIOHandlerSocket1.SocksInfo:=IdSocksInfo1;
IdHTTP1.IOHandler:=IdSSLIOHandlerSocket1;
end;
2: begin // SOCKS5
IdHTTP1.ProxyParams.ProxyServer:='';
IdHTTP1.ProxyParams.ProxyPort:=0;
IdSocksInfo1.Version:=svSocks5;
IdSocksInfo1.Host:=Copy(Edit1.Text,1,Pos(':',Edit1.Text)-1);
IdSocksInfo1.Port:=StrToInt(Copy(Edit1.Text,Pos(':',Edit1.Text)+1,Length(Edit1.Text)));
IdSocksInfo1.Authentication:= saNoAuthentication;
IdSSLIOHandlerSocket1.SocksInfo:=IdSocksInfo1;
IdHTTP1.IOHandler:=IdSSLIOHandlerSocket1;
end;
end;
Code:=idhttp1.Get('https://yandex.ru');
// Delete(Code, 1, 150);
Memo1.Lines.Add(Code);
end;
procedure TForm1.FormCreate(Sender: TObject);
begin
SendMessage(GetWindow(ComboBox1.Handle,GW_CHILD), EM_SETREADONLY, 1, 0);
end;
procedure TForm1.IdHTTP1Work(ASender: TObject; AWorkMode: TWorkMode;
AWorkCount: Int64);
begin
Gauge1.Progress:=AWorkCount;
Application.ProcessMessages;
end;
procedure TForm1.IdHTTP1WorkBegin(ASender: TObject; AWorkMode: TWorkMode;
AWorkCountMax: Int64);
begin
Gauge1.MaxValue:=strtoint(Pars('Content-Length: ', idhttp1.Response.RawHeaders.Text, #13#10));
end;
end.