Dayakar Reddy
Dayakar Reddy

Reputation: 189

How to make soap post request using Volley library in Android

I want make to make soap post request using Volley library. I am using the following code and got error "HTTP/1.1 400 Bad Request". In previous I am using Soap library working fine but I need to make request using Volley library.I am using following url "http://test.com/TestApp/Services/service.asmx?op=ForgotPassword"

public void forgotPassword(final String userName,String url) {

        StringRequest sr = new StringRequest(Request.Method.POST,
                url,
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {

                        Toast.makeText(mContext, "Success" + response,
                                Toast.LENGTH_SHORT).show();
                    }
                }, new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        showResponse(error);
                    }
                }) {
            @Override
            protected Map<String, String> getParams() {
                Map<String, String> params = new HashMap<String, String>();

                params.put("Email", userName);
                params.put("Language", "en");


                return params;
            }

            @Override
            public Map<String, String> getHeaders() throws AuthFailureError {
                Map<String, String> params = new HashMap<String, String>();
                params.put("Content-Type", "application/x-www-form-urlencoded");
                params.put("Content-Length", "length");





                return params;
            }
        };
        Application.getInstance().getRequestQueue().add(sr);
    }

Please help me to make post soap request with volley.

Upvotes: 17

Views: 6290

Answers (2)

Devdatta
Devdatta

Reputation: 59

public void HttpPOSTRequestWithParam() {
RequestQueue queue = Volley.newRequestQueue(this);
String url = "http://www.yourwebstite.com/login.asp";
StringRequest postRequest = new StringRequest(Request.Method.POST, url, 
    new Response.Listener<String>() 
    {
        @Override
        public void onResponse(String response) {
            Log.d("Response", response);
        }
    }, 
    new Response.ErrorListener() 
    {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.d("ERROR","error => "+error.toString());
        }
    }
        ) {     

    @Override
    protected Map<String, String> getParams() 
    {  
        Map<String, String>  params = new HashMap<String, String>();
        params.put("grant_type", "password"); 
        // volley will escape this for you 

        params.put("username", "tester");  
        params.put("password", "Pass@123");

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

This is how you can make SOAP request using volley

Upvotes: 0

Dr.jacky
Dr.jacky

Reputation: 3567

First of all, I advise you to see exactly what you're sending by printing to the log.

If you want a StringRequest, you'll need to extend it and override getParams and getBody methods.

Please see this answer: https://stackoverflow.com/a/26270185/421467

Upvotes: 0

Related Questions