Reputation: 4268
I'm working on an application that uses HttpResponse for network calls.
Occasionally (about 30% of the time) network calls seem to fail with a 502 returning from the server. When checking the server logs, It appears that the server never received the request.
The logic doesn't seem bad, however, and it does work most of the time. I am communicating to the server via JSON.
HttpClient client = new DefaultHttpClient();
HttpPost method = new HttpPost( BASE_URL + endpoint )
...add json entity
method.addHeader( "content-type", "application/json" );
method.addHeader( "accept", "application/json" );
....call below function w client/method
protected HttpResponse invoke( HttpClient client, HttpUriRequest method ) throws ServiceException {
HttpResponse response = null;
try {
response = client.execute( method );
} catch ( //catch statements here ....)
int status = response.getStatusLine().getStatusCode();
//status = 502
}
The interesting thing about this call failing is that it's the exact same call across devices, and the server it's hitting is 20 feet away, although it does happen on a different server located in another state.
I can't see why it works sometimes but not others.
Upvotes: 1
Views: 3339
Reputation: 492
Run wire shark on both sender and receiver . Observe sends and receives. You should be able to see the cause of the problem.
If you are getting a 502 error it suggests an intermediate device ( proxy,web filter,etc ) is blocking or " eating " your HTTP post .
Upvotes: 2
Reputation: 47789
Hate to say it, but this just sounds like an infrastructure issue. Some networking problem between your device, and the server. The code itself looks fine
Upvotes: 0