处理soapUI特殊返回报文 【原】

String message =""
      
      + ""
      + ""
      +  "     "
      +  "        C33D61EF17  "
      +  "          "
      +  "        "
      +  "         "
      +  "               "
      +  "            QWSDEFRTGVFEDSWER  "
      +  "          63008080120150000001  "
      +  "            23008135920150000001  "
      +  "           1100.00  "
      +  "           2015-05-21  "
      +  "           2016-05-20  "
      +  "              "
      +  "          441225198006022516  "
      +  "           1  "
      +  "            2015-05-20 15:32:35  "
      +  "           4  "
      +  "             "
      +  "             "
      +  "              "
      +  "             "
      +  "              "
      +  "             "
      +  "             "
      +  "         "
      +  "      ]]>  "
      +  "       "
      +  "   "
      +  "";
        HttpClient httpclient = HttpClients.createDefault();
        HttpPost httppost = new HttpPost("http://10.15.22.120:8866/5700000002/ZHJDCBXSJAddCxSj/V1");//请求地址
        StringEntity content =new StringEntity(message, Charset.forName("UTF-8"));// 第二个参数,设置后才会对,内容进行编码
        content.setContentType("application/soap+xml; charset=UTF-8");//设置UTF-8编码
        content.setContentEncoding("UTF-8");
        httppost.setEntity(content);
        
        HttpResponse responses = null;
        Document doc = null;
        String queryResReceiveXml = null;
        String sentity = null;
        try {
            responses = httpclient.execute(httppost);//执行发送
            HttpEntity resEntity = responses.getEntity();
            if (resEntity != null) {
                sentity = EntityUtils.toString(resEntity, "UTF-8");//接受返回报文数据
                System.out.println("返回2报文:"+sentity);
                doc = XmlTool.getDocument(sentity, "UTF-8");//转换格式化
                Element eRoot = doc.getRootElement();
                Element body = eRoot.getChild("Body", eRoot.getNamespace());
                Element resp = (Element) body.getChildren().get(0);
                Element returnele = (Element) resp.getChildren().get(0);
                if(returnele != null){
                    queryResReceiveXml = returnele.getText().toString();
                }
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            System.out.println("返回报文:\n" + queryResReceiveXml);
        }

 

转载于:https://www.cnblogs.com/hmhhz/p/9663037.html

你可能感兴趣的:(处理soapUI特殊返回报文 【原】)