I'm writing a very simple download manager which just can Download
- Pause
- Resume
,
how is it possible to resume
the download from the exact point of the file that stop before, well actually the only thing I'm looking for is how to set the file pointer in server side and then I can download it from the exact point i wanted by InternetReadFile (Any Other Functions are accepted if you know a better way for it)
.
Although, InternetSetFilePointer Never works for me
:) and I don't want to use BITS.
I think this can be happen by sending a header but don't know what and how to send it.

- 32,350
- 30
- 109
- 146

- 21
- 1
- 5
1 Answers
You are looking for the Range
header. Use HttpAddRequestHeaders()
to add a custom Range
request header telling the server what range of bytes you want. See RFC 2616 Section 14.35 for syntax.
If the server supports ranges (use HttpQueryInfo(HTTP_QUERY_ACCEPT_RANGES)
to verify), it will send a 206
status code instead of a 200
status code (use HttpQueryInfo(HTTP_QUERY_STATUS_CODE)
to verify).
If 206
is received, simply seek your existing file to the resume position and then read the response data as-is to your file.
If 200
is received, the file is starting over from the beginning, so either:
truncate the existing file and start writing it fresh
seek the file, read and discard the response data until it reaches the desired position, then read the remaining data into your file.
Treat any other status code as a download failure.

- 1
- 1

- 555,201
- 31
- 458
- 770