发布XML请求和XML响应Volley库 [英] Post XML request and XML response Volley Library

查看:90
本文介绍了发布XML请求和XML响应Volley库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经集成了与JSON配合良好的排球库.现在,我正在尝试访问WCF SOAP,但我不知道如何将XML字符串作为请求传递,以及如何将XML字符串作为响应传递.

I have already integrated volley library working good with JSON. Now am trying to access WCF SOAP I do not know how to pass XML string as request and how to get XML string as response.

推荐答案

    // Tag used to cancel the request
    String  tag_string_req = "string_req";

    //String url = "URL......";



    final ProgressDialog pDialog = new ProgressDialog(this);
    pDialog.setMessage("Loading...");
    pDialog.show();

    StringRequest strReq = new StringRequest(Request.Method.POST,
            url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            Log.d(TAG, response.toString());
            pDialog.hide();

        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            VolleyLog.d(TAG, "Error: " + error.getMessage());
            pDialog.hide();
        }
    }){

        @Override
        public String getBodyContentType() {
            return "application/xml; charset=" +
                    getParamsEncoding();
        }

        @Override
        public byte[] getBody() throws AuthFailureError {
            String postData = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
                    "<sampletag>\n" +
                    "\t<sampletag>data</sampletag>\n" +
                    "</sampletag>"; // TODO get your final output
            try {
                return postData == null ? null :
                        postData.getBytes(getParamsEncoding());
            } catch (UnsupportedEncodingException uee) {
                // TODO consider if some other action should be taken
                return null;
            }
        }
        };

//将请求添加到请求队列 AppController.getInstance().addToRequestQueue(strReq,tag_string_req);

// Adding request to request queue AppController.getInstance().addToRequestQueue(strReq, tag_string_req);

这篇关于发布XML请求和XML响应Volley库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆