[fpc-pascal] Prorammatically sending file using HTTP POST?
Anthony Walter
sysrpl at gmail.com
Wed Apr 4 19:37:55 CEST 2018
Just a follow up, if care you get a response back from your POST, as in the
server says okay, you just use the same socket to read. Also, you might
need to call connect after you set the host:
var
Message: string;
Response: string;
...
// port 80 normally used for http
Socket.Connect('example.com', 80);
Socket.Send(Message);
Socket.Read(Response);
WriteLn(Response);
If the server accepted your POST, the response will start with 'HTTP 1.1
200 OK'#10, followed by some other headers. Socket Read might be named
Receive or Recv, depending on your client socket implementation of choice.
If you want to learn may, you may want to example my THttpClient object:
https://github.com/sysrpl/Cross.Codebot/blob/master/source/codebot.networking.web.pas#L532
And also, here is an example of how to write an object oriented socket
class that wraps the traditional socket apis on all platforms:
https://github.com/sysrpl/Cross.Codebot/blob/master/source/codebot.networking.pas#L84
If you look at that source you can also see how simple it is to add https
support to your socket.
Socket.Secure := True;
Socket.Connect('example.com', 443);
And finally, you don't need to use my github code. anyAclient socket class
for Pascal should work approximately the same.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20180404/0d600911/attachment.html>
More information about the fpc-pascal
mailing list