2

I m using Volley library for sending a request to server for Login to an app. it doesn't have any problem until couple of hours ago. but without any reason, i m getting this error "BasicNetwork.performRequest: Unexpected response code 429"

the code is this:

    public void loginRequest(final String username, final String password) {

    String URL = Misc.Server_Url() + "login";
    final StringRequest sr = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
        @Override
        public void onResponse(String response) {
            JSONObject obj;
            try {
                obj = new JSONObject(response);
                if (obj.getInt("success") == 1) {
                    startActivity(new Intent(ActivityLogin.this, ActivityArticles.class));
                    finish();
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
        }
    }) {
        @Override
        public Map<String, String> getHeaders() throws AuthFailureError {
            Map<String, String> params = new HashMap<>();
            params.put("Content-Type", "application/x-www-form-urlencoded");
            return params;
        }

        @Override
        protected Map<String, String> getParams() {
            Map<String, String> params = new HashMap<>();
            params.put("username", username.trim());
            params.put("password", password);
            return params;
        }

    };
    RetryPolicy policy = new DefaultRetryPolicy(2 * 1000, 2, 2);
    sr.setRetryPolicy(policy);
    AppController.getInstance().addToRequestQueue(sr);
}

I have searched in Wikipedia for this error (429) and i find that it means : "The user has sent too many requests in a given amount of time"

from server side(php) for more security if from an ip get more than for example 60 request within 10 second it will block that ip for a while... and client get 429 error code. i m wondering how it will occure when i send a single request to server same as above code!!! and in policy i set the try to 2 times Not more than that. i dont know why when i send this request i get error 429. means you have send 60 request within limited period of time.

do you know how to solve this problem? thanks in advance...

Hossein Mansouri
  • 752
  • 1
  • 13
  • 29
  • http://stackoverflow.com/questions/23146945/how-to-disable-volley-request-from-retrying – BNK Apr 30 '16 at 23:05
  • the maximum retry policy is set to 2 times. but i m getting this error from server, because of sending request more than 60 times in a limited time ex) 3 second... is my retry policy not working? or i had set it worng? – Hossein Mansouri May 01 '16 at 01:47
  • Try use some Rest client tool such as Postman to test that request with your server – BNK May 03 '16 at 08:22
  • i used httpRequester, when i use this only one request will send to server. but when i use volley sometime i get 429 error! – Hossein Mansouri May 03 '16 at 21:05

2 Answers2

2

Yes, as you said, the 429 response code states so. However, the tricky part is that the server sends this response code for either

  • You have sent too many requests in a short duration
  • The server has received too many requests by many others during that time

If you read the RFC related to the response code, you'll see that the RFC does not state that the server must identify individual users and only send them the busy status: 429. It could be because others are sending too many requests and the server is sending a 429 response to all.

In addition, the RFC states that the server should respond with a 429 response and the server MAY send the following parameter in its response header.

Retry-After: 3600

This would mean you should retry after this timeout.

Community
  • 1
  • 1
Ruchira Randana
  • 4,021
  • 1
  • 27
  • 24
-1

the reason was coz of caching system in server. if we send new request each time, it works fine. but if our request use from caching strategy system in server... it occur 429 error number...

Hossein Mansouri
  • 752
  • 1
  • 13
  • 29