File download question

jamie_pattison

Well-known member
Joined
Sep 9, 2008
Messages
116
Programming Experience
Beginner
Using a HTTPWebRequest with a Stream i can download files. What do i need to know if resuming downloads from where they were interrupted is supported?

Code wise i need to use AddRange and have that configured, however what is the priority order, i.e. If the server does not support resuming downloads, is there anything i can do or is that not important? How could i test the server if it does support resuming downloads (i know i need a 206 response but how could i test without writing further code?)

Thanks in advance
 
If you want to check prior to actually downloading you can issue a HEAD request, it is the same as for example a GET request with the difference that server only returns the headers and not the data.
 
Thanks JohnH. I could do that but before i continue with this project i would like to see if i could test this before writing further code, as if the server doesnt support it i may just stop there?
 
Considering the facts making a 1 byte request for partial content may be just as good idea.
 
I returned the headers for the HttpWebRequest, which came back with Authorisation: Basic XXXXXX and Host: download.site.com. So

1. Is this performing the same check?
2. If the answer to question 1 is yes then to me it seems the server doesnt support it.

If the server doesnt support resuming the download, then what could be the best way of caching the file on our server and then resuming from that point (Please note i have been searching on this but no direct answers to my questions)?

Thanks
 
A server may not identify if it supports ranges or not until you actually request one, thus the previous reply. Even with a HEAD request you may not be able to see if it would, even if it does.
what could be the best way of caching the file on our server and then resuming from that point
If the file is downloaded from start to a certain index you can resume from that index given the current file length, if not you need to keep information about what parts are downloaded so far and resume from that.
 
Back
Top