Alamofire progress returns -1 even though Content-Length is set

家住魔仙堡 提交于 2019-12-11 01:28:40

问题


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.

Why is it always saying -1?


回答1:


Try this,

Pass Accept-Encoding key in header.

It worked for me.

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
        }

Original answer



来源:https://stackoverflow.com/questions/37560461/alamofire-progress-returns-1-even-though-content-length-is-set

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!