How to make soap post request using Volley library in Android
Asked Answered
O

2

17

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.

Ophiolatry answered 27/11, 2014 at 7:16 Comment(1)
Hi, Dayakar did you got the answer you're looking, am also searching for the same. can we use volley for Soap web services ??Grum
M
0

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://mcmap.net/q/747135/-android-volley-post-string-in-body

Maddeu answered 18/11, 2015 at 7:38 Comment(0)
P
0
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

Pottage answered 20/9, 2018 at 6:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.