即使 Content-length 有值,totalBytesExpectedToRead 也返回 -1
我找到了相同的 problem在 stackoverflow 上,但没有得到答复
这是我的代码:
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 字节)。
似乎只有一次对进度 block 的调用,我会说 Alamofire 将 totalBytesExpectedToRead
设置为 -1 作为对服务器宣布的内容与实际发布的内容之间不一致的响应收到。
关于ios - Swift - Alamofire totalBytesExpectedToRead 返回 -1,即使设置了 Content-length,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39847042/