Strange problem with connection timeouts and Google Volley

I have an Android app that uses Google Volley to query the web server server ( http://www.example.com/request.php ). The code requesting the web page is called when the user moves the map.

The problem is that sometimes the request fails. When it fails, I open the Chrome browser (also on the phone) and go to this page "request.php". The request fails with a connection timeout error. Then I click update in Chrome and it loads correctly. I open the application again, and then everything works fine again, that is: the request passes.

The steps I took to debug:

  • I switched from com.loopj Async library to Google Volley -> there were still timeout errors

  • Another page is requested (for example: stackoverflow.cominstead example.com/request.php) when moving the map → without errors

  • Added this line for htaccess on the server: RewriteRule (.*) - [E=Cache-Control:no-cache]because I had problems with the cache x-litespeed cache serving cached pages until → there were still timeout errors

  • Tried on several Android devices and emulators → still has timeout errors

  • Filed a ticket with my web host asking if they noticed any timeout errors from my page → , they said

Here is my code:

public void updateMarkers() {
    params = new HashMap<String, String>();
    params.put("mykey", "myvalue");
    StringRequest fpsr = new StringRequest(Method.POST, "http://www.example.com/request.php", new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            //do stuff with the response
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            //do stuff with error
        }
    }) {
        @Override
        protected Map<String, String> getParams() {
            return params;
        }
    };
    ApplicationController.getInstance().addToRequestQueue(fpsr, "updateMarkers");
}    

And ApplicationController.javais the same as here: http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

, , , , .

, - , . Chrome Android -, , .

- ? !

, HTTP VolleyError. , , , -. , error.networkResponse.statusCode ; - .

+4

All Articles