【问题标题】:How to make soap post request using Volley library in Android如何在 Android 中使用 Volley 库进行肥皂发布请求
【发布时间】:2015-01-25 17:17:35
【问题描述】:

我想使用 Volley 库发出肥皂帖子请求。我正在使用以下代码并收到错误“HTTP/1.1 400 Bad Request”。在以前,我使用 Soap 库工作正常,但我需要使用 Volley 库发出请求。我正在使用以下 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);
    }

请帮我用凌空发出 postsoap 请求。

【问题讨论】:

  • 嗨,Dayakar 你得到了你正在寻找的答案吗,我也在寻找同样的答案。我们可以将 volley 用于 Soap 网络服务吗??

标签: android soap android-volley


【解决方案1】:

首先,我建议您通过打印到日志来准确查看您发送的内容。

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

请看这个答案:https://stackoverflow.com/a/26270185/421467

【讨论】:

    【解决方案2】:
    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);}
    

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-04-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多