5

I've created a volley request to receive HTTPS backend.

RequestQueue queue = Volley.newRequestQueue(uiCallback.getContext(),
    new SSLVerification().getHurlStack(uiCallback.getContext()));

JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET,
    requestUrl, null, new Response.Listener<JSONObject>() {
    ...
}
req.setRetryPolicy(new DefaultRetryPolicy(3_600_000, 0, 0));

queue.add(req);

In the manifest, I have added the Internet permission as follows:

<uses-permission android:name="android.permission.INTERNET" />

Everything works fine with requests that take only a short while.

But if the response comes over 3 minutes after the request, then the application receives nothing.

On the backend, I've set a breakpoint. After 3 minutes, I've let backend to send a response to the app, but there nothing comes. No success, no error, just nothing.

If I make an HTTP request without SSLVerification, then I receive a response also after 6 minutes. Instead, HTTPS requests longer than 3 minutes just don't want to work.

Change RetryPolicy to make many requests it's just a workaround and it's not an option.

Davide Cannizzo
  • 2,826
  • 1
  • 29
  • 31
anatoli
  • 1,663
  • 1
  • 17
  • 43
  • Please try cache strategy.... https://stackoverflow.com/questions/16781244/android-volley-jsonobjectrequest-caching/16852314. I am not sure but It can be helpful. – rockstar May 02 '19 at 11:19
  • Try the api in HTTPS using Postman, see if you get any response there. See the logs using onErrorResponse in volley too. – Sambit Mallick May 02 '19 at 12:48
  • this is the case. with postman https works also by 5 minutes. In **Volley** comes after 3 minutes **nothing** – anatoli May 02 '19 at 14:55

3 Answers3

4

The response is taking too long to be received in the device and thus the Volley is having a TimeoutError. You need to modify the default timeout value like the following before sending a request to your server.

req.setRetryPolicy(new RetryPolicy() {
    @Override
    public int getCurrentTimeout() {
        return 360000;
    }

    @Override
    public int getCurrentRetryCount() {
        return 5000;
    }

    @Override
    public void retry(VolleyError error) throws VolleyError {

    }
});

queue.add(req);
Reaz Murshed
  • 23,691
  • 13
  • 78
  • 98
  • I have already set `req.setRetryPolicy(new DefaultRetryPolicy(3_600_000, 0, 0));` the first value is `Timeout`, that i set to **1 hour**. But self after 3 Minutes there comes nothing back – anatoli May 02 '19 at 07:04
  • Three minutes is a long time. Are you sure that the context did not go out of scope at that time while you might be browsing other activities? What does your logcat say? Does your code prints any error or verbose message which is unusual? Please post your logcat if that does. And btw, did you try setting up the timeout like the way I have suggested? Its actually working for me for a long wait. – Reaz Murshed May 02 '19 at 07:09
  • while the request is view blocked. I see ProgressBar. If i set the url to **HTTP** instead **HTTPS** then response works also after 6 minutes. By **HTTPS** there comes in logback **nothing** back. Your solution i have not tryed yet. – anatoli May 02 '19 at 07:29
  • Please try with the solution first and let me know if you see anything unusual in the logcat. If there is anything, please post it here. – Reaz Murshed May 02 '19 at 07:31
  • Still not working. No response is coming. Logs are empty – anatoli May 02 '19 at 10:41
1

Try this

req.setRetryPolicy(new DefaultRetryPolicy(90000, 1, 1f));
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
0

If I make an HTTP request without SSLVerification, then I receive a response also after 6 minutes. Instead, HTTPS requests longer than 3 minutes just don't want to work.

Can this indicate if your server is timing out?

Occasionally, Volley fails to return a response from the server

Dinesh
  • 948
  • 6
  • 11