[fpc-pascal] Prorammatically sending file using HTTP POST?

Graeme Geldenhuys mailinglists at geldenhuys.co.uk
Sat Apr 7 11:25:25 CEST 2018


On 2018-04-07 10:20, Graeme Geldenhuys wrote:
> And if you are really lazy... ;-)

And here's an even simpler version.


-------- [ from Remy Lebeau ]-------------------------


TIdHTTP has two overloaded versions of Post() that take a filename as input:

var
  Response: String;

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

....or....

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 posting to an HTTPS URL, so you need to first assign
an SSL-enabled IOHandler, such as TIdSSLIOHandlerSocketOpenSSL, to the
TIdHTTP.IOHandler property beforehand.

-------------------[ end ]------------------------

Can't get simpler than that!

Regards,
  Graeme

-- 
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp


More information about the fpc-pascal mailing list