I am developing an android app and using retrofit to send requests and get responses. Like this:
public interface Service {
@POST("/GetInfo")
InfoResponse getInfo(@Body InfoRequest request);
}
I want to know how much data it will be used when doing these requests.
I find if I set the LogLevel for retrofit, it could print out the size in log.
For request:
---> HTTP POST http://.... Content-Type: application/json; charset=UTF-8 Content-Length: 516 ---> END HTTP (522-byte body)
For response:
<--- HTTP 200 http://.... :HTTP/1.1 200 OK Content-Type: application/json <--- END HTTP (420394-byte body)
This 522-byte and 420394-byte information what I want. Is there any way to get it directly without getting the log and parsing it?
If I have to use this log in order to calculate the size, any good way to get the size from log and then show on android?
Thanks!
You can add network intecepter in you retrofit builder and check size using
responseBody.source().apply{request(Long.MAX_VALUE)}.buffer.size
for response
and request.body.contentLength()
for request
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With