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();
}
}