0

I am trying to call Rest-APIs in android. But it gives me connection time-out error in real device most of the time. From 5 tries it return me 4 time this error.

While the same thing work perfect in Emulator. I have tried Rest-APIs calling using different techniques(Volley, HttpClient, Retrofit), but same error returned.

I have deployed Rest-APIs in GoDaddy server.

StringRequest strReq = new StringRequest(Method.GET, url,
            getSuccessListener(listener), getErrorListener(listener)) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<String, String>();
            params.put("Authorization", Authorization);
            return params;
        }
    };
    strReq.setRetryPolicy(new DefaultRetryPolicy(15 * 1000, 5,
            DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
    queue.add(strReq);
gunr2171
  • 16,104
  • 25
  • 61
  • 88
Monika Patel
  • 2,287
  • 3
  • 20
  • 45

1 Answers1

0

If you are connecting to Rest api using your own code then do the following.

Increase connection time out using

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(15000);  // time is in milliseconds
conn.setConnectTimeout(15000);  // so this will wait for 15 seconds

This may solve your problem.

If you are using valley then check this answer

Community
  • 1
  • 1
ELITE
  • 5,815
  • 3
  • 19
  • 29