【问题标题】:AFNetworking progressAF联网进展
【发布时间】:2012-03-03 23:56:10
【问题描述】:

我正在尝试使用 AFHTTPRequestOperation 类的setDownloadProgressBlock。回调给了我 3 个参数:

( NSInteger bytesRead , NSInteger totalBytesRead , NSInteger totalBytesExpectedToRead ) 

为了让我获得进度,我需要 totalBytesExpectedToRead 值,但它给了我一个 -1。我检查了 HTTP 响应的标头,内容长度在那里...

{
    "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";
}

这是 AFNetworking 框架的问题吗?

【问题讨论】:

    标签: objective-c ios cocoa-touch afnetworking


    【解决方案1】:

    请检查以下响应,这是与 gzip 格式内容相关的 NSURLConnection 的限制:https://stackoverflow.com/a/7426735/250164

    【讨论】:

    • 您好,感谢您的意见。有没有办法可以关闭这个 gzip?
    • 我不建议这样做,但这是你必须在服务器上禁用的东西。我个人宁愿让我的响应加载得更快,而不是让进度指示器向我显示加载所需的时间(也就是说,除非有问题的数据首先不适合 gzip 压缩,比如图像数据,这是已压缩)。
    • 您应该能够在客户端禁用它,方法是通过请求标头指示您不接受 gzip 数据。
    • 添加不带参数的标题“Accept-Encoding:”应该可以解决问题。
    • 在 GET 之前执行 HEAD 请求将为您提供所需的信息。
    猜你喜欢
    • 2015-11-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-02
    • 1970-01-01
    • 1970-01-01
    • 2020-06-22
    相关资源
    最近更新 更多