0

In my Android application I run a http post and I get timeout exception when i am connected via 3G/4G and not via wifi (I send images but this happened with images of 1 Kb as well, the problem it's not the size of image, I am sure about this).

Here the code.

I use Android Asynchronous Http Client

Thanks in advance.

    AsyncHttpClient httpClient = new AsyncHttpClient();
    RequestParams requestParams = new RequestParams();
    httpClient.setTimeout(25000);
    httpClient.setConnectTimeout(25000);
    httpClient.setResponseTimeout(25000);
    destination = new File(path);
    requestParams.put("file", destination);
    httpClient.post("http://" + serverUrl + ":8081/readplate", requestParams, new JsonHttpResponseHandler() {

                @Override
                public void onFailure(int statusCode, Header[] headers, java.lang.Throwable throwable, org.json.JSONObject response) {
                   //exception here
                   ...

                }

                @Override
                public void onSuccess(int statusCode, Header[] headers, org.json.JSONArray response) {

                    ...

                }
    }
Stephane Landelle
  • 6,990
  • 2
  • 23
  • 29
alfo888_ibg
  • 1,847
  • 5
  • 25
  • 43

1 Answers1

0

As Mark suggests in the comments, it may be a network issues rather than your code and this is definitely the first place to look. For example, the port you are using, 8081, may be blocked by your operator for some reason.

One way to ensure it is not your code itself causing the problem is to use a browser based POST tool like Postman on a a laptop which has WiFI and an 3G dongle - link below. Alternatively, you could use a REST client on your Android device to do the same test - link below also. Test on WiFi and on 3G/4G and if you see the same problem you are seeing with your app you can most likely assume the problem is not with your code.

Postman link:

REST client for Android:

Mick
  • 24,231
  • 1
  • 54
  • 120