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