Howto neglect these bytes while downloading file from http server
-
The four bytes look like the number of bytes in the remainder of the message.
-
ChrisW67: You are right. That's the data length. The problem was in the below lines:
QDataStream out(&file); out << bytes;
When bytes are written to QDataStream in this fashion, Its write the content length followed by the actual data. (I thought it will just write the content).
So i figured out to use QDataStream::writeRawData
QDataStream out(&file); size_t size = bytes.size(); out.writeRawData(bytes, size); file.close();
-
Why do you need a QDataStream then at all?
-
I don't actually need it if i just use it for downloading a file, In fact, it is easier to just use QFile::write(..) in the above case. I though it would be easier to prefix/suffix files content like below:
out << prefix;
out << file;
out << suffix -
If you use QDataStream on the sender side you must also use it on the receiver side. Everything else will break sooner or later.
-
@Christian-Ehrlicher : I didn't notice that, can you please elaborate it a little.
-
Don't know what else I should say - you use QDataStream to create your stream so you have to use QDataStream to deserialize the data later on. QDataStream adds data to the stream (as you already noticed) and may alter your data in any way: "A data stream is a binary stream of encoded information which is 100% independent of the host computer's operating system, CPU or byte order. For example, a data stream that is written by a PC under Windows can be read by a Sun SPARC running Solaris."
So reading it as raw data may or may not work. The format of QDataStream's binary representation is not documented so you it can change. -
oky. thank you :)
12/12