-
Notifications
You must be signed in to change notification settings - Fork 3
Examples
ZRazor edited this page Apr 5, 2013
·
2 revisions
Get Example #1:
var
HTTP: THTTPSender;
s: string;
begin
HTTP := THTTPSender.Create(nil);
HTTP.DefaultEncoding := TEncoding.ANSII; // By default it is also ANSII
s := HTTP.Get('http://zt.am/');
ShowMessage(s);
HTTP.Free;
end;
Get Example #2 Using Stream:
var
HTTP: THTTPSender;
Stream: TStringStream;
begin
HTTP := THTTPSender.Create(nil);
Stream := TStringStream.Create('', TEncoding.ANSII);
HTTP.Get('http://zhyk.ru/', Stream);
if Stream.size > 0 then begin
Stream.Seek(0, 0);
ShowMessage(Stream.ReadString(Stream.size));
end;
HTTP.Free;
Stream.Free;
end;
Post Example + Setting Some Headers and Proxy:
var
HTTP: THTTPSender;
s: string;
begin
HTTP := THTTPSender.Create(nil);
HTTP.Headers.UserAgent := 'Mozilla 2.0';
HTTP.Headers.AcceptEncoding := 'gzip, deflate';
HTTP.ConnectTimeout := 6000; // 6 sec
HTTP.ReadTimeout := 10000; // 10 sec
HTTP.SendTimeout := 0; // unlimited
HTTP.Proxy := '70.60.50.40:8080';
s := HTTP.Post('http://zt.am/', 'user=ololoev&pass=123456');
ShowMessage(HTTP.Response.RawHeaders)
ShowMessage(HTTP.ResponseText); // = ShowMessage(s);
HTTP.Free;
end;
var
Data:TStringList;
//....
begin
//....
Data := TStringList.Cteate;
Data.Add('user=ololoev');
Data.Add('pass=123456');
HTTP.Post('http://zt.am/',Data);
//...
end;
Loading file on imglink.ru Example:
var
Cont: THTTPPostContainer;
HTTP: THTTPSender;
s: string;
begin
Cont := THTTPPostContainer.Create;
Cont.AddFile('image1', 'myimg.png', 'application/octet-stream');
Cont.AddFormField('tags1', 'No tags');
Cont.AddFormField('user_uniq_key', 'yes');
HTTP := THTTPSender.Create(nil);
HTTP.Post('http://imglink.ru/process.php', Cont);
ShowMessage(HTTP.ResponseText);
Cont.Free;
HTTP.Free;
end;