I'm using okhttp to send requests to my server. The problem is that the requests okhttp sends are missing the content-length header - I can set the header manually with:
Request.builder
....
.addHeader("content-length","some-value")
but I can't get the appropriate value to put there. If I try to measure the body of my request like this:
int request_length = body.length();
builder.addHeader("content-length", String.valueOf(request_length));
then okhttp doesn't add the header at all.
Is there a correct way of adding the content-length header to requests (preferably a way of adding the header "by default")?
It's automatic if your ResponseBody returns a content length other than -1.
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