Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send POST data to a webserver?
#8
(05-01-2018, 07:43 PM)BosseB Wrote: I have switched on debugging in FireFox and run a session via the web form.

This is what I caught:

And, have you captured TIdHTTP's output, like I described earlier?

Quote:assign one of Indy's TIdLog... components to the TIdHTTP.Intercept property to see Indy's HTTP traffic

It is not worth capturing the web browser's output if you don't also capture TIdHTTP's output for comparison.

Based on the code you have shown so far, and the changes I suggested, TIdHTTP should be outputting something like this:

Code:
POST /firmware HTTP/1.0
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------050118161753994
Content-Length: 304674
Host: 192.168.119.249
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://192.168.119.249/firmware
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0

----------050118161753994
Content-Disposition: form-data; name="update"; filename="DHT_MONITOR.bin"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

<file data here>
----------050118161753994--

One thing I notice that is missing from TIdHTTP's output that is present in Firefox's output is the "Authorization" header. By default, TIdHTTP will not transmit authentication credentials unless the server asks for them (in which case, you need to enable the hoInProcessAuth flag in the TIdHTTP.HTTPOptions property), or you set the TIdHTTP.Request.BasicAuthentication property to True (it is False by default).

So, try enabling authentication in your TIdHTTP so the Request.Username and Request.Password are actually sent to the server. TIdHTTP's output should then look more like this:

Code:
POST /firmware HTTP/1.0
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------050118161840615
Content-Length: 304674
Host: 192.168.119.249
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Referer: http://192.168.119.249/firmware
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:59.0) Gecko/20100101 Firefox/59.0
Authorization: Basic YWdpYWRtaW46YWdpdXNh

----------050118161840615
Content-Disposition: form-data; name="update"; filename="DHT_MONITOR.bin"
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary

<file data here>
----------050118161840615--

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, 10:35 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)