即使设置了Content-Length,Alamofire进度也会返回-1 [英] Alamofire progress returns -1 even though Content-Length is set
本文介绍了即使设置了Content-Length,Alamofire进度也会返回-1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我从Alamofire progress
调用中打印出预期的字节数时,它始终会打印-1直到最后一刻为止(在打印总字节数时).但是,如果我对Web服务器运行curl命令,则会得到标头输出,其中很清楚地列出了Content-Length标头.
When I print out the expected bytes from an Alamofire progress
call it always prints -1 until the very end, when it prints the total. However, if I run a curl command against the webserver I get header output which very clearly lists the Content-Length header.
为什么总是说-1?
推荐答案
尝试一下,
在标头中传递接受编码键.
Pass Accept-Encoding key in header.
对我有用.
let headers = ["Accept-Encoding" : ""]
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
}
这篇关于即使设置了Content-Length,Alamofire进度也会返回-1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文