模拟SoapUI发送XML,返回并处理逻辑(Webservice调用)

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

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值