Skip to content

Instantly share code, notes, and snippets.

@viniciussanchez
Last active October 7, 2025 23:14
Show Gist options
  • Select an option

  • Save viniciussanchez/7df51da431302865db739b64bdf61c0e to your computer and use it in GitHub Desktop.

Select an option

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;
@guiltmg
Copy link

guiltmg commented Oct 7, 2025

how to add bearer token in request?

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