April 4, 2011
Everyone seems to need some POST
Well, after about four unrelated requests to make a POST example, I finally managed to add some basic POST functionality to the HTTP visual client example. There’s a new POST editbox for your POST data (you need it url-encoded! like “a=10&b=20” or “name=First+Second”). You then just check the Use POST checkbox and Send Request as usual. I’ll try to make the example even more nice later but this should suffice for now.
The steps needed for POST to work are roughly:
1. Set HTTP.Method to hmPOST
2. Assign HTTP.OnCanWrite event handler
3. Set HTTP.ContentLength = SizeOf(your POST data)
4. Do HTTP.AddExtraHeader(‘Content-Type: application/x-www-form-urlencoded’); for basic url-encoded POST, or other if you need something else
5. Do HTTP.SendRequest
6. Inside HTTP.OnCanWrite handler, do aSocket.Send or aSocket.SendMessage to send your data
7. Inside HTTP.OnCanWrite handler, change OutputEof to wsPendingData if not all data was sent
7. Inside HTTP.OnCanWrite handler, change OutputEof to wsDone if all data was sent (you need to set it at any rate!)
This should be it. I hope everyone now has a better picture of how to use POST with lNet’s HTTP.