I have to stream data over a singlepart HTTP request in real time. The targeted device only handle data when request is like:
POST ...
Content-Type:...
Content-Length:9999999
Connection:Keep-Alive
Cache-Control:no-cache
Authorization:...
<data>
<data>
<data>
...
In Java, I have to do some hack to make it works using the setFixedLengthStreamingMode(9999999);
function on my HttpURLConnection
object. Then I create the request and populate body data with a BufferedOutputStream
object.
Now, I'm trying to develop a Qt based application to transmit data to this device but I can't achieve it. I tried something like:
QNetworkRequest networkRequest;
networkRequest.setUrl(/*...*/);
// Set some headers
networkRequest.setHeader(QNetworkRequest::ContentLengthHeader, "9999999");
QIODevice* pIoDevice = new QBuffer(this);
pIoDevice->open(QIODevice::ReadWrite);
QNetworkAccessManager* pNetworkAccessManager = new QNetworkAccessManager(this);
pNetworkAccessManager->post(networkRequest, pIoDevice);
// Then exec current run loop to wait until I manually stop it.
On a other hand, when my producer give me data to transmit I's like to made something like:
pIoDeviceData->write(/* data */);
Problem is that reading network traces (using Wireshark), I see that the Content-Length
emitted is equal to 0
so the device closes the connection and I get an error code NetworkError::RemoteHostClosedError
; So I missed something but what? Any idea?