AFNetworking progress

2019-05-17 05:48发布

问题:

I am trying to use setDownloadProgressBlock of AFHTTPRequestOperation class. The call back gives me 3 parameters:

( NSInteger bytesRead , NSInteger totalBytesRead , NSInteger totalBytesExpectedToRead ) 

In order for me to get the progress, I need the totalBytesExpectedToRead value, but it's giving me a -1. I checked the headers of the HTTP response and the content length is there...

{
    "Cache-Control" = "no-store, no-cache, must-revalidate, post-check=0, pre-check=0";
    Connection = "Keep-Alive";
    "Content-Encoding" = gzip;
    "Content-Length" = 36902;
    "Content-Type" = "text/plain";
    Date = "Sat, 03 Mar 2012 23:53:11 GMT";
    Expires = "Thu, 19 Nov 1981 08:52:00 GMT";
    "Keep-Alive" = "timeout=5, max=95";
    "Last-Modified" = "Sat, 03 Mar 2012 23:53:11 GMT";
    Pragma = "no-cache";
    Server = "Apache/2.2.20 (Ubuntu)";
    Vary = "Accept-Encoding";
    "X-Powered-By" = "PHP/5.3.6-13ubuntu3.3";
}

Is this a problem with the AFNetworking framework?

回答1:

Please check the following response, it's a limitation of NSURLConnection related to the content being in gzip format: https://stackoverflow.com/a/7426735/250164