How to write contents of a QTcpSocket to a binary file?
Hi all
i wrote a program that by HTTP protocol , connect to a download host and download a specific file.
for connection i used a QTcpSocket that connect to port 80 and send HTTP request,
when receive data from host, i don't know how to saves content of file not whole of received data to a binary file
please help me!
Regards.
Re: How to write contents of a QTcpSocket to a binary file?
If I understand correctly, you want to know how to extract the contents of the file from the HTTP reply. This amounts to reimplementing (at least a part of) the HTTP protocol on top of QTcpSocket. Why don't you use the implementation (QNetworkAccessManager and related classes) already provided by Qt?
Re: How to write contents of a QTcpSocket to a binary file?
bkz i love QTcpSocket
lol
:D
Re: How to write contents of a QTcpSocket to a binary file?
With all due respect, this seems to me like a very wrong reason for reinventing the wheel. You would save yourself hundreds of lines of code and tens of hours of coding/debugging/maintenance by using an existing implementation, especially when it is well documented like Qt's. Anyway your question is not directly related to Qt, but to the HTTP.
Re: How to write contents of a QTcpSocket to a binary file?
Quote:
Originally Posted by
Ali Reza
i don't know how to saves content of file not whole of received data to a binary file
1. open file
2. if needed, preprocess the downloaded data according to the protocol your are using
3. write content of the downloaded data to the file
4. close file
To do #2, you need to:
1. learn about HTTP
2. learn about Base64 and GZIP/DEFLATE
3. learn about MIME
...or just change your affections and use QNetworkAccessManager.
Re: How to write contents of a QTcpSocket to a binary file?
@ wysota
hello sir
please explain a little about "Base64 and GZIP/DEFLATE"
thanks in advance.
Re: How to write contents of a QTcpSocket to a binary file?