0

using the delegate

- (void)connection: (NSURLConnection*) connection didReceiveResponse: (NSHTTPURLResponse*) response {

the download size can be fetched as a long long with this:

downloadSize = [response expectedContentLength];

But my downloadSize is sometimes -1. Sometimes it is the correct value but half of the time it returns -1.

This answer on stackoverflow shows a possible solution and explains why I get the value -1: why [response expectedContentLength] always return -1.

I tried:

NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:_downloadURL] cachePolicy:NSURLRequestReloadIgnoringLocalAndRemoteCacheData timeoutInterval:60];
[request setValue:@"" forHTTPHeaderField:@"Accept-Encoding"]; //Don't use Gzip to see total size of download

But that doesn't change a thing. Does anyone know why expectedContentLength give me the value -1? Again it only give me -1 half of the time i try. Sometimes it is oke.

EDIT I logged [response AllHeaderFiles] in DidReceiveResponse when I use the code

[request setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];

"Content-Type" = "text/html";
Date = "Mon, 16 Sep 2013 12:43:54 GMT";
Server = "Apache/2";
"Transfer-Encoding" = Identity;
Vary = "Accept-Encoding,User-Agent";
"X-Powered-By" = "PHP/5.2.17";

This is the output without that code:

Connection = "keep-alive";
"Content-Encoding" = gzip;
"Content-Length" = 1500;
"Content-Type" = "text/html";
Date = "Mon, 16 Sep 2013 12:38:56 GMT";
Server = "Apache/2";
Vary = "Accept-Encoding,User-Agent";
"X-Powered-By" = "PHP/5.2.17";

But both outputs stay the same regardless if I get the -1 or the download size.

Community
  • 1
  • 1
Mark Molina
  • 5,057
  • 8
  • 41
  • 69
  • Well i've found that some time the content-size header is not set for the server response. Can you check whether the server response headers are set correctly? – rckoenes Sep 16 '13 at 12:31
  • Forget my last edit. I commented the setting Gzip code to "". Changed it now – Mark Molina Sep 16 '13 at 12:41

0 Answers0