William Melani
William Melani

Reputation: 4268

HttpResponse returns a 502 Error, doesn't appear to hit endpoint

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

Answers (2)

stimpy
stimpy

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

Joel Martinez
Joel Martinez

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

Related Questions