How to upload a file using http post? Delphi 2009

My goal is to upload a text file via an HTTP message. I am using Delphi 2009.

Say for example to the following URL

https://www.example.com/ex/exampleAPI.asmx/Process

I understand that this can be done using the TIdHttp component. And the next challenge

IdHttp1.Post(); 

But I can’t understand how to configure everything, that is, specify the URL and include the file for publication.

Thanks.

+7
source share
1 answer

TIdHTTP has two overloaded versions of Post() that accept the file name as input:

 var Response: String; Response := IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt'); 

.

 var Response: TStream; Response := TMemoryStream.Create; IdHTTP1.Post('https://www.example.com/ex/exampleAPI.asmx/Process', 'c:\filename.txt', Response); ... Response.Free; 

Note that you are sending an HTTPS URL, so you must first assign an SSL-enabled TIdSSLIOHandlerSocketOpenSSL , such as TIdSSLIOHandlerSocketOpenSSL , to the TIdHTTP.IOHandler property.

+8
source

All Articles