Skip to content

Instantly share code, notes, and snippets.

@viniciussanchez
Last active January 17, 2024 17:29
Show Gist options
  • Save viniciussanchez/7df51da431302865db739b64bdf61c0e to your computer and use it in GitHub Desktop.
Save viniciussanchez/7df51da431302865db739b64bdf61c0e to your computer and use it in GitHub Desktop.
How to send multipart/form-data with Delphi using THTTPClient
uses System.Net.HttpClient, System.Net.Mime;
function Send: string;
var
LRequest: THTTPClient;
LFormData: TMultipartFormData;
LResponse: TStringStream;
begin
LRequest := THTTPClient.Create;
LFormData := TMultipartFormData.Create();
LResponse := TStringStream.Create;
try
LFormData.AddField('myJson', '{"id":1,"user":"Vinicius Sanchez"}');
LFormData.AddFile('myFiles', 'C:\Samples\FormData\File.pdf'); // You can also use the AddStream method if it's available
LRequest.Post('myUrl', LFormData, LResponse);
Result := LResponse.DataString;
finally
LFormData.Free;
LResponse.Free;
LRequest.Free;
end;
end;
@WolfstarUAfDrog
Copy link

may more comments

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment