Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to send POST data to a webserver?
#14
(05-03-2018, 10:18 PM)BosseB Wrote: Magic byte:
In both the FireFox and the Config App cases I am choosing the exact same file for transfer.

Then it should be transferred as exactly the same bytes in both Firefox and TIdHTTP.

The ONLY other difference I can think of is if the IoT device is not correctly handling the "Content-Transfer-Encoding: binary" header that TIdHTTP sends for the file but Firefox does not send. You can instruct Indy not to send that header by clearing the TIdFormDataField.ContentTransfer property (AddFiles() defaults it to 'binary'), eg:

Code:
Src.AddFile('update', FileName).ContentTransfer := '';

(05-03-2018, 10:18 PM)BosseB Wrote: I checked the log for the start and end of the file transfer data and verified that these are the same as the binary start and end bytes of the file itself.

I agree that the feedback indicates that a byte is not arriving as it should, but I cannot understand how that can happen since the source file is the same in both cases. And the submitting form is simplicity itself, I can see nothing there that can affect how the file data are modified...

The webform itself is not the issue. How the webform is formatted during transmission is. And there is something in TIdHTTP's formatting that the IoT device clearly does not like/handle correctly.

(05-03-2018, 10:18 PM)BosseB Wrote: OTOH, the destination function inside the IoT device will do the following during/after receiving the data:

Do you have access to the IoT device's source code for its HTTP server? Or any kind of debugging tool for analyzing how it is processing HTTP requests?

(05-03-2018, 10:18 PM)BosseB Wrote: Should I add a final GET in order to retrieve the result data being sent back

No. However, on a successful POST, the IoT device is sending back HTML that redirects a web browser back to the webform after 15 seconds. You can choose whether that is appropriate for your app or not.

(05-03-2018, 10:18 PM)BosseB Wrote: is that already part of the HTTP.Post function?

Yes, the result data is in the POST's response.

(05-03-2018, 10:18 PM)BosseB Wrote: I opened the logfile and the binary flash file in HxD to check the contents.
The bin file starts with the E9 magic byte and it is 304464 bytes in size.
The bin file ends with this sequence: 0C FF 3F 00 00 00 CA

In the log file I find the E9 start byte in address $274 (628 decimal)
And the ending sequence is located with CA at address 4A814
So if I calculate the transferred file data length I get 4A814 +1 - 274 = 4A5A1 (or 304545 decimal)

This means that the data transferred are 81 bytes too many....

Not necessarily. TIdMultipartFormDataStream transmits file data as-is, it doesn't modify the bytes in any way, or inject any extra bytes. You can use Wireshark to verify that (if you set the TIdFormDataField.ContentTransfer property to 'base64' or 'quoted-printable', it will encode the bytes accordingly, but it will not alter them, so the receiver should see the original bytes correctly after decoding).

However, Indy's logging could be translating $0D and $0A bytes into text, for instance. When it comes to binary data, what is logged may not be exactly what is transmitted. That is why I suggested setting the TIdLogFile.ReplaceCRLF property to false to avoid that.

(05-03-2018, 10:18 PM)BosseB Wrote: There seems to be inserted bytes within the file body.

You are just going to have to compare all 304545 bytes against the original 304464 bytes to check what is actually being changed. But, it would certainly make sense that if the file bytes are being messed up during transmission, the IoT device will fail verification and ignore the file.

(05-03-2018, 10:18 PM)BosseB Wrote: Or else these are protocol inserted bytes?

There are no "protocol inserted bytes" in file uploads via HTML webform.

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-03-2018, 11:09 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)