问题
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