April 4, 2011

Everyone seems to need some POST

Posted in Uncategorized at 20:04 by almindor

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
OR
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.

Advertisements

4 Comments »

  1. Dibo said,

    Nice tutorial. Should be included in lNet package.
    BTW: I have proposition for lHTTP. I think more people like me using this same client instance for more than one request. On each request I need to clear extra headers because session token between server changed. I could not find a solution to clear extra headers so I wrote patch for this:
    http://bugs.freepascal.org/view.php?id=18954

    • almindor said,

      Thanks for the patch, I’ll notify Micha about it since it’s his domain. He seems to be more active lately. If he doesn’t respond to it in some time, feel free to bug me about it 😀

  2. User said,

    Hello.
    almindor, does lNet Package work in Delphi? Or only Free Pascal (Lazarus).
    Thanks.

    • almindor said,

      lNet doesn’t work in Delphi since it was written using specific FPC functions.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: