totalBytesExpectedToRead

totalBytesExpectedToRead

即使Content-length有值,totalBytesExpectedToRead也会返回-1

我在stackoverflow上找到了相同的problem,但未得到答复

这是我的代码:

Alamofire.download(.POST, urlString, headers: headers, destination: destination)
       .progress { bytesRead, totalBytesRead, totalBytesExpectedToRead in
            print("totalBytesRead: \(totalBytesRead)")
            print("totalBytesExpectedToRead: \(totalBytesExpectedToRead)\n\n")
        }
        .response { request, response, data, error in
        }

服务器响应:
Access-Control-Allow-Origin →*
Access-Control-Expose-Headers →Link
Connection →keep-alive
Content-Length →163
Content-Type →application/json; charset=utf-8
Date →Tue, 04 Oct 2016 07:12:56 GMT

结果:
totalBytesRead: 1211
totalBytesExpectedToRead: -1

最佳答案

服务器发送给您的内容肯定有问题:宣布的Content-Length(163字节)比您实际收到的(1211字节)小。

似乎只有一个对进度块的调用,我想说Alamofire将totalBytesExpectedToRead设置为-1,以响应服务器宣布的内容和接收的内容之间的不一致性。

关于ios - Swift-Alamofire totalBytesExpectedToRead即使设置了Content-length也返回-1,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39847042/

10-15 06:36