02.Mirth Connect client API 调用

距离上次写mirth的博客已经好长时间了,一直找不到状态。这几天经过小永同学的帮忙,写了一个调用clientapi的实例。希望大家指导。

1,client api地址:https://121.42.147.xxx:8445/api/。是swagger搞的(一款RESTFUL接口的文档在线自动生成+功能测试功能软件,很厉害)有兴趣的同志可以研究一下。


2,接口调用,一个POST


登录接口调用地址:https://121.42.147.xxx:8445/api/users/_login

下面就是代码了

public String sendHttps(String url, String xml, String type, String method)
			throws Exception {
		String result = "";
		try {
			HttpURLConnection connection = null;
			InputStream response = null;
			CSAX509KeyManager[] tm = { new CSAX509KeyManager() };
			SSLContext sslContext = SSLContext.getInstance("SSL", "SunJSSE");
			sslContext.init(null, tm, new java.security.SecureRandom());
			SSLSocketFactory sslFactoryJavax = sslContext.getSocketFactory();
			javax.net.ssl.HttpsURLConnection
					.setDefaultSSLSocketFactory(sslFactoryJavax);
			javax.net.ssl.HttpsURLConnection
					.setDefaultHostnameVerifier(new ProxyHostNameVerifier());
			connection = (HttpURLConnection) new URL(url).openConnection();
			connection.setReadTimeout(300);
			connection.setUseCaches(false);
			connection.setDoInput(true);
			connection.setDoOutput(true);
			connection.setRequestMethod(method);
			connection.setRequestProperty("Content-Type", type);
			connection.setRequestProperty("Content-Length",
					String.valueOf(xml.length()));
			connection.connect();
			PrintWriter out = new PrintWriter(connection.getOutputStream());
			out.print(xml);
			out.flush();
			out.close();
			response = connection.getInputStream();
			String line = null;
			StringBuffer sb = new StringBuffer();
			BufferedReader br = new BufferedReader(new InputStreamReader(
					response));
			while ((line = br.readLine()) != null) {
				sb.append(line);
			}
			result = sb.toString();
			br.close();
			response.close();
			out.close();
			connection.disconnect();
		} catch (Exception ex) {
			ex.printStackTrace();
			throw ex;
		}
		return result;
	}
看起来还是挺简单的

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值