2

I am facing a weird issue with my android application. Sometimes, the server gets a POST HTTP request with just the headers and no body. I am using Retrofit 2.2 on android with OkHttpClient 3.6. In server side logs I can see that the content-length is > 0. From my understanding, content-length is just body size in bytes, which again adds to the confusion over what's happening.

My First guess was to see if something is going wrong on retrying POST requests. But having gone through the RetryAndFollowupInterceptor.java and PR #1259 and PR #2479, I don't think that is the problem.

My Second guess was that maybe the requests get cancelled the mid-way, like uploading a image but user closes the app, this could be a possibility. I tried to reproduce this scenario but was unsuccessful with Emulators running API 16 and API 26 and a Moto G device running Android 24.

I've seen that most of my API calls take around 1 second on 3G networks. I've even tried on emulators with setting of a 2G network and poor strength but couldn't reproduce the error.

I just wanted to know whether it's possible that the server receives only headers in some cases and no body? or the HTTP protocol itself sends headers and body differently? Could it be the case that body is getting stripped out by some server(uses PHP) config? I can think of some optimization, for large body sizes like a multipart request, which HTTP possibly be doing but some of my body is just {"id":12345}.

Has anyone faced any similar issue?

Amit Barjatya
  • 249
  • 3
  • 14

1 Answers1

0

we are seeing the same thing with tcp connections. header shows a sizable body is about to follow, but then we get an empty body. we were able to reduce this (but not eliminate it) by placing a dreaded thread.wait(500) after the tcplistener gets the connection. be warned however the wait causes other problems expecially around the capacity of the socket as all connections now potentially hang around for half a second.

why it needs the wait I cannot explain. theory is the socket is still receiving and needs a few milliseconds to hand it all over to the listening application.

Leon
  • 1