Delphi component wrapper for WinInet library. Written in Delphi 2010.
procedure TForm1.Button1Click(Sender: TObject);
begin
if HttpRequest1.Get('https://httpbin.org/get') then
ShowMessage(HttpRequest1.Response.ContentAsString)
else
ShowMessage('ERROR ' + IntToStr(HttpRequest1.Response.StatusCode));
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
if HttpRequest1.Post('https://httpbin.org/put', 'testing a POST') then
ShowMessage(HttpRequest1.Response.ContentAsString)
else
ShowMessage('ERROR ' + IntToStr(HttpRequest1.Response.StatusCode));
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Body: TMultipartFormBody;
begin
Body := TMultipartFormBody.Create;
Body.ReleaseAfterSend := True;
Body.Add('code', '2');
Body.AddFromFile('image', 'C:\Users\User\Desktop\image.png');
HttpRequest1.Post('https://httpbin.org/post', Body);
ShowMessage(HttpRequest1.Response.ContentAsString);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
Body: TUrlEncodedFormBody;
begin
Body := TUrlEncodedFormBody.Create;
Body.ReleaseAfterSend := True;
Body.Add('code', '1');
Body.Add('name', 'John');
HttpRequest1.Post('https://httpbin.org/post', Body);
ShowMessage(HttpRequest1.Response.ContentAsString);
end;
- Method 1
HttpRequest1.Username := 'admin';
HttpRequest1.Password := '123';
- Method 2
HttpRequest1.Get('http://admin:[email protected]');
ShowMessage(HttpRequest1.Response.ContentAsString);
- Added the possibility to send data using GET method, similar to POST;
- Added ContentType parameter to methods that can send raw text;
- Added Basic Authentication (URL inline OR username and password).
- Solved bug that don't return Content-Length.