Volley is not working with SOAP api in Android

321 Views Asked by At

Hi All I am using Volley and trying to parse data from SOAP api. Following is my snippet code, when I try to parse data it is giving error. Can any one help me with this? I am getting following error every time.

E/Volley: [7440] BasicNetwork.performRequest: Unexpected response code 400 for

 public void HttpPOSTRequestWithParam() {
        RequestQueue queue = Volley.newRequestQueue(this);
        String url = "https://www.myweb.co.ke/Wt/webtask.asmx?op=GetProductListing";
        StringRequest postRequest = new StringRequest(Request.Method.POST, url,
                new Response.Listener<String>()
                {
                    @Override
                    public void onResponse(String response) {
                        Log.e("Response", response);
                    }
                },
                new Response.ErrorListener()
                {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        Log.e("ERROR","error => "+error.toString());
                    }
                }
        ) {

            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                params.put("UserName", "John");



                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();


                params.put("User Name", "1234");
                params.put("Password", "4321");




                return params;
            }
        };
        queue.add(postRequest);}
1

There are 1 best solutions below

4
Michael Dougan On

You may need to tell it how the Content-Type and Accept headers are encoded. Here the parameter string should look like: 'grant_type=password&username=apikey&password=apipassword'

    @Override
    protected Map<String, String> getParams() 
    {  
            Map<String, String>  params = new HashMap<String, String>();  
            params.put("grant_type", "password");
            params.put("username", "apikey");
            params.put("password", "apipassword");

            return params;  
    }

   @Override
   public Map<String, String> getHeaders() throws AuthFailureError {
       HashMap<String, String> headers = new HashMap<String, String>();
            headers.put("Accept", "application/x-www-form-urlencoded; charset=UTF-8");
            headers.put("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
       return headers;
   }