Last active
January 17, 2024 17:29
-
-
Save viniciussanchez/7df51da431302865db739b64bdf61c0e to your computer and use it in GitHub Desktop.
How to send multipart/form-data with Delphi using THTTPClient
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
may more comments