response expectedContentLength return -1

后端 未结 2 650
清酒与你
清酒与你 2020-12-01 20:08

Hello i need to create a progressView when i load data from my webservice.

Actually the expectedContentLength alway return -1.

After look lots of similary pr

相关标签:
2条回答
  • 2020-12-01 20:50

    I got the same problem it seems like the expected file size is unknown thats why it returns -1.

    see similar threat why [response expectedContentLength] always return -1

    0 讨论(0)
  • 2020-12-01 20:57

    Ok i've fix it myself here is my real problem and a solution :

    When i ask with Curl i can get the length no problem.

    But when i use NSurlConnection

    NSURLConnection *c = [[NSURLConnection alloc] initWithRequest:req delegate:self];
    

    The response will be compress with "Gzip" (don't ask me why). And if the response is encode with Gzip it's impossible to know the length, then "expectedContentLength" return -1. And "Content-Length" is absent from [response allHeaderFields].

    If you really want to get the length you can simply force to not use Gzip like this :

    [req setValue:@"" forHTTPHeaderField:@"Accept-Encoding"];
    
    0 讨论(0)
提交回复
热议问题