如何在Android中使用Volley库制作soap post请求

时间:2014-11-27 07:16:35

标签: android soap android-volley

我想使用Volley库制作肥皂贴请求。我使用以下代码并得到错误" HTTP / 1.1 400 Bad Request"。在之前我使用Soap库工作正常,但我需要使用Volley库提出请求。我正在使用以下网址" 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);
    }

请帮我用排球制作肥皂请求。

2 个答案:

答案 0 :(得分:0)

首先,我建议您通过打印到日志来确切了解您要发送的内容。

如果你想要一个StringRequest,你需要扩展它并覆盖getParams和getBody方法。

请参阅此答案:https://stackoverflow.com/a/26270185/421467

答案 1 :(得分: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);}

这是使用排球发出SOAP请求的方法