import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import javax.jws.WebService;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPMessage;
import org.apache.xml.security.utils.Base64;
import org.kohsuke.rngom.digested.Main;
public class Test
{
public static void main(String[] args) throws Exception {
String urlString = "url地址";
String xmlFile = "D://axis//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);
String author = "Basic " + Base64.encode(("rfc_user:init1234").getBytes());
httpConn.setRequestMethod("POST"); // 请求方式
httpConn.setDoOutput(true); // 向服务器发送数据
httpConn.setDoInput(true); // 获取服务端的响应
httpConn.setRequestProperty("Content-Type", "text/xml;charset=UTF-8");
httpConn.setReadTimeout(5000); // 读取超时
httpConn.setConnectTimeout(5000); // 服务器响应超时
httpConn.setUseCaches(false); // 不使用缓存
httpConn.setRequestProperty("Authorization", author);
OutputStream out = httpConn.getOutputStream();
out.write(buf);
// System.out.println(new String(buf));
out.close();
InputStreamReader is = new InputStreamReader(httpConn.getInputStream(),"utf-8");
BufferedReader in = new BufferedReader(is);
String inputLine;
System.out.println("123");
while ((inputLine = in.readLine()) != null)
{
System.out.println(inputLine);
}
in.close();
httpConn.disconnect();
}
}
标签:XML,xml,java,Webservice,httpConn,SoapUI,new,import,String From: https://blog.51cto.com/u_14906615/5899424