Search code examples
androidparametersheaderandroid-volleyhttp-status-code-400

Android Volley code 400


I'm trying to post data to website. It is login operation. I check form data hidden tag etc. In form data there is a hidden input _RequestVerificationToken. That's why first, I made get request to parse _RequestVerificationToken and for headers.

StringRequest _StringRequest = new StringRequest(Request.Method.GET, url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                       //Parsing Process
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        error.printStackTrace();
                    }
                }
           )
            {
            @Override
            protected Response<String> parseNetworkResponse(NetworkResponse response) {

                headers=response.headers;
                return super.parseNetworkResponse(response);
            }
        };

After all i made post request with parameters and headers:

@Override
            public Map<String, String> getParams()
            {
                Map<String, String>  params = new HashMap<>();
                // the POST parameters:
                params.put("Password", password);
                params.put("RememberMe", "false");
                params.put("ReturnUrl", url_post);
                params.put("UserName",username);
                params.put(name,_RequestVerificationToken);
                return params;
            }
            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                              return headers;
            }

I check form data by using fiddler extension in chrome. I checked parameters again and again but it returned code 400. Can you show me what is the problem?


Solution

  • I solve the problem with this class and I added this:

     CookieManager cookieManager = new CookieManager(new PersistentCookieStore(this), CookiePolicy.ACCEPT_ORIGINAL_SERVER);
                CookieHandler.setDefault(cookieManager);
    

    before add request to queue