I'm trying to upload a binary (mp3) file using an HTTP post session.
The file is read-out using File.ReadAllBytes and the content bytes are set on the session data parameter using protocol.SetParameterBinary
To test this upload I've created a dummy mp3 file containing some simple binary content (Hex 02 01 00 02 00). Using this file I can easily perform an upload via the Web Interface and compare the request payload with the payload send via protocol communication.
The request via the Web Interface gives the expected result:
However when performing the same call via protocol it seems the payload data is completely different and I'm even losing a byte along the way.
I'm certain the protocol.SetParameterBinary call works correctly and my session content parameter is filled in with the correct binary data (I've performed a Set and Get count on the bytes and the result was identical: 5 bytes)
I have a feeling SLPort is changing the content somehow by possible adding some extra encoding to the data, but it would be nice if someone could confirm this?
I've implemented and performed the same HTTP upload request directly from QAction (bypassing SLPort) and everything works perfectly, which only confirms my SLPort suspicion.
Am I missing something, or can somebody confirm the above?
When the Content-Type header doesn't contain a charset, the data is automatically encoded as UTF-8. In this case that's not desired because you want to send the raw binary data without any conversions. This can be achieved by adding a charset so the Content-Type header.
<Header key="Content-Type">text/plain; charset=ISO-8859-1</Header>
More details can be found here: https://docs.dataminer.services/develop/schemadoc/Protocol/Protocol.HTTP.Session.Connection.Request.Headers.Header.html#remarks