简体   繁体   中英

How can I get the number of actual bytes transferred with OkHttp3?

OkHttp does a great job of transparently handling GZIP content encoding. When I call response.body().contentLength() I get the decoded size of the response.

How can I get the number of bytes actually transferred in the HTTP response?

Alternately, getting the value from the original Content-Length header would do.

I am trying to keep track of how many bytes I have downloaded over a metered connection.

Look at EventListener, which tracks bytes transmitted over the network.

https://square.github.io/okhttp/events/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM