views:

253

answers:

2

I am having trouble trying to do a partial get request using NSURLMutableRequest.

I set up the header values as follows:

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:url];
NSString* range = [NSString stringWithFormat:@"bytes %d-%d/%d", receivedContentLength, expectedContentLength, expectedContentLength];
[request setHTTPMethod:@"GET"];
[request addValue:[fmt stringFromDate:[NSDate date]] forHTTPHeaderField:@"Date"];
[request addValue:@"application/octet-stream" forHTTPHeaderField:@"Content-Type"];
[request addValue:@"bytes" forHTTPHeaderField:@"Accept-Ranges"];
[request addValue:range forHTTPHeaderField:@"Content-Range"];
[request addValue:[NSString stringWithFormat:@"%d", (expectedContentLength - receivedContentLength)] forHTTPHeaderField:@"Content-Length"];

I have validated (using WGet) that the url that i am using supports partial get requests. The reason I cannot use the resume functionality of NSURLDownload is that it requires the eTag, something that the server doesn't currently support.

Am I missing something with the way I am setting up the header??

Thanks!

A: 

Ok figured out what it was. I was getting a temporarily moved redirect response to which I created a new response with the original range headers and the new redirect ones. I also changed "Content-Range" tag to "Range".

Yah - Now I can support wget style resumes! Suppose I should add an if-unmodified-since but not right now ;)

A: 

Hi Colin,

I'm dealing with the same problem.Can you please post your working code to let me see how to resume a download.

Thanks.

Can