Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send POST data to a webserver?
#2
(04-30-2018, 09:56 PM)BosseB Wrote: This is a continuation of a thread at Embarcadero forum, which no longer responds to my input...

That is because the forums server has been offline for a few days is no longer usable.

(04-30-2018, 09:56 PM)BosseB Wrote: When I use the method above then there is no error message or such generated, and there is also no debug message from the IoT device saying that update is in progress. In fact once the method is done nothing has happened on the IoT device. It looks like the IoT server is quietly disregarding the call.

So something is clearly missing here, but what?

At first glance, the code you have shown looks OK, provided you are posting to the same URL that generates the HTML webform, since that is where the <form> element is asking web browsers to post to.

I suggest you run a packet sniffer (such as Wireshark) on your client machine and look at the actual HTTP traffic that a web browser generates vs what TIdHTTP generates when communicating with your IoT device.  There is obviously going to be a difference between the two, but you are not going to see that just looking at code.

One difference that comes to mind would be if the IoT device uses cookies during the webform submission.  Your code is not currently handling that possibility.  Simply set TIdHTTP.AllowCookies=True, then call TIdHTTP.Get() to retrieve the HTML webform and any associated cookies, before then calling TIdHTTP.Post() to post the webform.  It will automatically send back any matching cookies.

Another possible difference is some web servers don't like Indy's default "User-Agent" request header.  If the IoT device is similar, you might need to change the value of the TIdHTTP.Request.UserAgent property to mimic a known web browser.

(04-30-2018, 09:56 PM)BosseB Wrote: How does one simulate the action of a form submission in a web browser but using Indy components in a FPC/Lazarus program?

You already are.  The correct solution is to use TIdHTTP.Post() with a TStrings or TIdMultipartFormDataStream, depending on the "enctype" of the <form> element.  You just have to make sure that you are including everything in your request that a web browser would include.

Reply


Messages In This Thread
How to send POST data to a webserver? - by BosseB - 04-30-2018, 09:56 PM
RE: How to send POST data to a webserver? - by rlebeau - 05-01-2018, 12:34 AM

Forum Jump:


Users browsing this thread: 2 Guest(s)