JAVA 调用 WebService接口

封装webservice 的 工具类:

/** 
* @author  作者 : 小布
* @version 创建时间 : 2019年7月16日 上午9:49:01 
* @explain 类说明 : 
*/
public class WebServiceUtil {

    @SuppressWarnings({ "unchecked", "unlikely-arg-type" })
	public static Map<String, Object> getWebService(Map<String, Object> param) throws IOException {  
		long startTime=System.currentTimeMillis();
		Map<String, Object> mp = new ConcurrentHashMap<>(10000000);
		URL url = new URL("");//webservice接口  
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();  
        connection.setRequestMethod("POST");  
        connection.setRequestProperty("content-type", "text/xml;charset=utf-8");  
        connection.setDoInput(true);  
        connection.setDoOutput(true);  
        String soapXML = getXML(param);  
        OutputStream os = connection.getOutputStream();  
        os.write(soapXML.getBytes());  
        int responseCode = connection.getResponseCode();  
        if(200 == responseCode){
            InputStream is = connection.getInputStream();  
            InputStreamReader isr = new InputStreamReader(is);  
            BufferedReader br = new BufferedReader(isr);  
            StringBuilder sb = new StringBuilder();  
            String temp = null;  
            while(null != (temp = br.readLine())){  
                sb.append(temp);  
            }  
            is.close();  
            isr.close();  
            br.close();    
            sb.toString();//返回值      
        }
        os.close();
        mp.put("code", responseCode);
        long endTime=System.currentTimeMillis();
        mp.put("time", (endTime-startTime)+"ms");
		return mp;
    }  
      
    public static String getXML(Map<String, Object> param){  
        String soapXML = "";//请求的XML参数
        return soapXML;  
    } 
	
}

相关推荐
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页