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