java发送soapui格式的报文


import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;

使用java对soapui报文进行发送 

public class Test

{

    @Test
    public void TestOne() throws Exception {
        String urlString = ip+端口+接口; //请求地址
       
String xmlFile = "D:\\test.xml";//发送soapui报文路径
       
URL url = new URL(urlString);
        HttpURLConnection httpConn = (HttpURLConnection) url.openConnection();
        File fileToSend = new File(xmlFile);
        byte[] buf = new byte[(int) fileToSend.length()];//用于存放文件数据的数组
       
new FileInputStream(xmlFile).read(buf);
        httpConn.setRequestProperty("Content-Type", "application/soap+xml; charset=utf-8");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        OutputStream out = httpConn.getOutputStream();
        out.write(buf);
        out.close();
        InputStreamReader is = new InputStreamReader(httpConn.getInputStream(),"utf-8");
        BufferedReader in = new BufferedReader(is);
        String inputLine;
        while ((inputLine = in.readLine()) != null)

        {

           //根据响应字段判断状态是否正确
           
if(inputLine.indexOf("状态一") != -1)
            {
                System.out.println("最终结果1:描述一");
                break;
            }
            if(inputLine.indexOf("状态二") != -1)
            {
                System.out.println("最终结果1:描述二");
                break;
            }
        }
        in.close();
        httpConn.disconnect();
    }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM