




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、eoLinker-API Shop 常见疾病查询 Java调用示例代码常见疾病查询提供所患疾病的病因、症状、检查、用药、治疗、并发症等方面的详细分析资料该产品拥有以下APIs:获取疾病部位列表通过部位获取疾病列表关键字获取疾病列表获取疾病列表查询疾病信息通过症状获取疾病列表注意,该示例代码仅适用于 HYPERLINK 网站下API 使用该产品前,您需要通过 HYPERLINK /#/api/detail/?productID=215 /#/api/detail/?productID=215 申请API服务1.获取疾病部位列表package net.apishop.www.controller;
2、import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObjec
3、t;/* * httpUrlConnection访问远程接口工具 */public class Api /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(String url, String requestMethod, Map params) InputStream
4、is = null; try String parameters = ; boolean hasParams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true; if (hasParams) parameters = parameters.substring(0, pa
5、rameters.length() - 1); / 请求方式是否为get boolean isGet = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); / 请求的参数类型(使用restlet框
6、架时,为了兼容框架,必须设置Content-Type为“”空) conn.setRequestProperty(Content-Type, application/octet-stream); / conn.setRequestProperty(Content-Type, application/x-www-form-urlencoded); / 设置连接超时时间 conn.setConnectTimeout(50000); / 设置读取返回内容超时时间 conn.setReadTimeout(50000); / 设置向HttpURLConnection对象中输出,因为post方式将请求参数放
7、在http正文内,因此需要设置为ture,默认false if (isPost) conn.setDoOutput(true); / 设置从HttpURLConnection对象读入,默认为true conn.setDoInput(true); / 设置是否使用缓存,post方式不能使用缓存 if (isPost) conn.setUseCaches(false); / 设置请求方式,默认为GET conn.setRequestMethod(requestMethod); / post方式需要将传递的参数输出到conn对象中 if (isPost) DataOutputStream dos =
8、 new DataOutputStream(conn.getOutputStream(); dos.writeBytes(parameters); dos.flush(); dos.close(); / 从HttpURLConnection对象中读取响应的消息 / 执行该语句时才正式发起请求 is = conn.getInputStream(); catch(UnsupportedEncodingException e) e.printStackTrace(); catch(MalformedURLException e) e.printStackTrace(); catch(IOExcept
9、ion e) e.printStackTrace(); return is; public static void main(String args) String url = /common/postcode/getPostCodeByAddr; String requestMethod = POST; Map params = new HashMap(); params.put(apiKey,your_api_key); /需要从获取 String result = null; try InputStream is = httpRequestToStream(url, requestMet
10、hod, params); byte b = new byteis.available(); is.read(b); result = new String(b); catch(IOException e) e.printStackTrace(); if (result != null) JSONObject jsonObject = JSONObject.parseObject(result); String status_code = jsonObject.getString(statusCode); if (status_code = 000000) / 状态码为000000, 说明请求
11、成功 System.out.println(请求成功: + jsonObject.getString(result); else / 状态码非000000, 说明请求失败 System.out.println(请求失败: + jsonObject.getString(desc); else / 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println(发送请求失败); 2.通过部位获取疾病列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IO
12、Exception;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/* * httpUrlConnection访问远程接口工具 */public class A
13、pi /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(String url, String requestMethod, Map params) InputStream is = null; try String parameters = ; boolean hasP
14、arams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true; if (hasParams) parameters = parameters.substring(0, parameters.length() - 1); / 请求方式是否为get boolean isGe
15、t = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); / 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Content-Type为“”空) conn.setRequestPr
16、operty(Content-Type, application/octet-stream); / conn.setRequestProperty(Content-Type, application/x-www-form-urlencoded); / 设置连接超时时间 conn.setConnectTimeout(50000); / 设置读取返回内容超时时间 conn.setReadTimeout(50000); / 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认false if (isPost) conn.set
17、DoOutput(true); / 设置从HttpURLConnection对象读入,默认为true conn.setDoInput(true); / 设置是否使用缓存,post方式不能使用缓存 if (isPost) conn.setUseCaches(false); / 设置请求方式,默认为GET conn.setRequestMethod(requestMethod); / post方式需要将传递的参数输出到conn对象中 if (isPost) DataOutputStream dos = new DataOutputStream(conn.getOutputStream(); dos
18、.writeBytes(parameters); dos.flush(); dos.close(); / 从HttpURLConnection对象中读取响应的消息 / 执行该语句时才正式发起请求 is = conn.getInputStream(); catch(UnsupportedEncodingException e) e.printStackTrace(); catch(MalformedURLException e) e.printStackTrace(); catch(IOException e) e.printStackTrace(); return is; public sta
19、tic void main(String args) String url = /common/postcode/getPostCodeByAddr; String requestMethod = POST; Map params = new HashMap(); params.put(apiKey,your_api_key); /需要从获取 params.put(page, ); /当前页码(默认1) params.put(pageSize, ); /该页疾病数量(默认15) params.put(site, ); /发病部位 String result = null; try InputS
20、tream is = httpRequestToStream(url, requestMethod, params); byte b = new byteis.available(); is.read(b); result = new String(b); catch(IOException e) e.printStackTrace(); if (result != null) JSONObject jsonObject = JSONObject.parseObject(result); String status_code = jsonObject.getString(statusCode)
21、; if (status_code = 000000) / 状态码为000000, 说明请求成功 System.out.println(请求成功: + jsonObject.getString(result); else / 状态码非000000, 说明请求失败 System.out.println(请求失败: + jsonObject.getString(desc); else / 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println(发送请求失败); 3.关键字获取疾病列表package net.apishop.www.controller;impo
22、rt java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map;import com.alibaba.fastjson.JSONObject;/*
23、 * httpUrlConnection访问远程接口工具 */public class Api /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(String url, String requestMethod, Map params) InputStream is =
24、 null; try String parameters = ; boolean hasParams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true; if (hasParams) parameters = parameters.substring(0, parame
25、ters.length() - 1); / 请求方式是否为get boolean isGet = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection) u.openConnection(); / 请求的参数类型(使用restlet框架时,为
26、了兼容框架,必须设置Content-Type为“”空) conn.setRequestProperty(Content-Type, application/octet-stream); / conn.setRequestProperty(Content-Type, application/x-www-form-urlencoded); / 设置连接超时时间 conn.setConnectTimeout(50000); / 设置读取返回内容超时时间 conn.setReadTimeout(50000); / 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在htt
27、p正文内,因此需要设置为ture,默认false if (isPost) conn.setDoOutput(true); / 设置从HttpURLConnection对象读入,默认为true conn.setDoInput(true); / 设置是否使用缓存,post方式不能使用缓存 if (isPost) conn.setUseCaches(false); / 设置请求方式,默认为GET conn.setRequestMethod(requestMethod); / post方式需要将传递的参数输出到conn对象中 if (isPost) DataOutputStream dos = new
28、 DataOutputStream(conn.getOutputStream(); dos.writeBytes(parameters); dos.flush(); dos.close(); / 从HttpURLConnection对象中读取响应的消息 / 执行该语句时才正式发起请求 is = conn.getInputStream(); catch(UnsupportedEncodingException e) e.printStackTrace(); catch(MalformedURLException e) e.printStackTrace(); catch(IOException
29、e) e.printStackTrace(); return is; public static void main(String args) String url = /common/postcode/getPostCodeByAddr; String requestMethod = POST; Map params = new HashMap(); params.put(apiKey,your_api_key); /需要从获取 params.put(page, ); /当前页码(默认1) params.put(pageSize, ); /该页疾病数量(默认15) params.put(ke
30、yword, ); /关键字 String result = null; try InputStream is = httpRequestToStream(url, requestMethod, params); byte b = new byteis.available(); is.read(b); result = new String(b); catch(IOException e) e.printStackTrace(); if (result != null) JSONObject jsonObject = JSONObject.parseObject(result); String
31、 status_code = jsonObject.getString(statusCode); if (status_code = 000000) / 状态码为000000, 说明请求成功 System.out.println(请求成功: + jsonObject.getString(result); else / 状态码非000000, 说明请求失败 System.out.println(请求失败: + jsonObject.getString(desc); else / 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println(发送请求失败); 4.获
32、取疾病列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.M
33、ap;import com.alibaba.fastjson.JSONObject;/* * httpUrlConnection访问远程接口工具 */public class Api /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(String url, String
34、 requestMethod, Map params) InputStream is = null; try String parameters = ; boolean hasParams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true; if (hasParams)
35、 parameters = parameters.substring(0, parameters.length() - 1); / 请求方式是否为get boolean isGet = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection)
36、u.openConnection(); / 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Content-Type为“”空) conn.setRequestProperty(Content-Type, application/octet-stream); / conn.setRequestProperty(Content-Type, application/x-www-form-urlencoded); / 设置连接超时时间 conn.setConnectTimeout(50000); / 设置读取返回内容超时时间 conn.setReadTimeout(50000); /
37、设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认false if (isPost) conn.setDoOutput(true); / 设置从HttpURLConnection对象读入,默认为true conn.setDoInput(true); / 设置是否使用缓存,post方式不能使用缓存 if (isPost) conn.setUseCaches(false); / 设置请求方式,默认为GET conn.setRequestMethod(requestMethod); / post方式需要将传递的参数输出到co
38、nn对象中 if (isPost) DataOutputStream dos = new DataOutputStream(conn.getOutputStream(); dos.writeBytes(parameters); dos.flush(); dos.close(); / 从HttpURLConnection对象中读取响应的消息 / 执行该语句时才正式发起请求 is = conn.getInputStream(); catch(UnsupportedEncodingException e) e.printStackTrace(); catch(MalformedURLExceptio
39、n e) e.printStackTrace(); catch(IOException e) e.printStackTrace(); return is; public static void main(String args) String url = /common/postcode/getPostCodeByAddr; String requestMethod = POST; Map params = new HashMap(); params.put(apiKey,your_api_key); /需要从获取 params.put(page, ); /当前页码(默认1) params.
40、put(pageSize, ); /该页疾病数量(默认15) String result = null; try InputStream is = httpRequestToStream(url, requestMethod, params); byte b = new byteis.available(); is.read(b); result = new String(b); catch(IOException e) e.printStackTrace(); if (result != null) JSONObject jsonObject = JSONObject.parseObject
41、(result); String status_code = jsonObject.getString(statusCode); if (status_code = 000000) / 状态码为000000, 说明请求成功 System.out.println(请求成功: + jsonObject.getString(result); else / 状态码非000000, 说明请求失败 System.out.println(请求失败: + jsonObject.getString(desc); else / 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.prin
42、tln(发送请求失败); 5.查询疾病信息package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;im
43、port java.util.Map;import com.alibaba.fastjson.JSONObject;/* * httpUrlConnection访问远程接口工具 */public class Api /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(St
44、ring url, String requestMethod, Map params) InputStream is = null; try String parameters = ; boolean hasParams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true
45、; if (hasParams) parameters = parameters.substring(0, parameters.length() - 1); / 请求方式是否为get boolean isGet = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (Htt
46、pURLConnection) u.openConnection(); / 请求的参数类型(使用restlet框架时,为了兼容框架,必须设置Content-Type为“”空) conn.setRequestProperty(Content-Type, application/octet-stream); / conn.setRequestProperty(Content-Type, application/x-www-form-urlencoded); / 设置连接超时时间 conn.setConnectTimeout(50000); / 设置读取返回内容超时时间 conn.setReadTi
47、meout(50000); / 设置向HttpURLConnection对象中输出,因为post方式将请求参数放在http正文内,因此需要设置为ture,默认false if (isPost) conn.setDoOutput(true); / 设置从HttpURLConnection对象读入,默认为true conn.setDoInput(true); / 设置是否使用缓存,post方式不能使用缓存 if (isPost) conn.setUseCaches(false); / 设置请求方式,默认为GET conn.setRequestMethod(requestMethod); / pos
48、t方式需要将传递的参数输出到conn对象中 if (isPost) DataOutputStream dos = new DataOutputStream(conn.getOutputStream(); dos.writeBytes(parameters); dos.flush(); dos.close(); / 从HttpURLConnection对象中读取响应的消息 / 执行该语句时才正式发起请求 is = conn.getInputStream(); catch(UnsupportedEncodingException e) e.printStackTrace(); catch(Malf
49、ormedURLException e) e.printStackTrace(); catch(IOException e) e.printStackTrace(); return is; public static void main(String args) String url = /common/postcode/getPostCodeByAddr; String requestMethod = POST; Map params = new HashMap(); params.put(apiKey,your_api_key); /需要从获取 params.put(diseaseID,
50、); /疾病ID String result = null; try InputStream is = httpRequestToStream(url, requestMethod, params); byte b = new byteis.available(); is.read(b); result = new String(b); catch(IOException e) e.printStackTrace(); if (result != null) JSONObject jsonObject = JSONObject.parseObject(result); String statu
51、s_code = jsonObject.getString(statusCode); if (status_code = 000000) / 状态码为000000, 说明请求成功 System.out.println(请求成功: + jsonObject.getString(result); else / 状态码非000000, 说明请求失败 System.out.println(请求失败: + jsonObject.getString(desc); else / 返回内容异常,发送请求失败,以下可根据业务逻辑自行修改 System.out.println(发送请求失败); 6.通过症状获取疾
52、病列表package net.apishop.www.controller;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.UnsupportedEncodingException;import .HttpURLConnection;import .MalformedURLException;import .URL;import .URLEncoder;import java.util.HashMap;import java.util.Map
53、;import com.alibaba.fastjson.JSONObject;/* * httpUrlConnection访问远程接口工具 */public class Api /* * 方法体说明:向远程接口发起请求,返回字节流类型结果 * param url 接口地址 * param requestMethod 请求方式 * param params 传递参数 重点:参数值需要用Base64进行转码 * return InputStream 返回结果 */ public static InputStream httpRequestToStream(String url, String r
54、equestMethod, Map params) InputStream is = null; try String parameters = ; boolean hasParams = false; / 将参数集合拼接成特定格式,如name=zhangsan&age=24 for (String key : params.keySet() String value = URLEncoder.encode(params.get(key), UTF-8); parameters += key + = + value + &; hasParams = true; if (hasParams) p
55、arameters = parameters.substring(0, parameters.length() - 1); / 请求方式是否为get boolean isGet = get.equalsIgnoreCase(requestMethod); / 请求方式是否为post boolean isPost = post.equalsIgnoreCase(requestMethod); if (isGet) url += ? + parameters; URL u = new URL(url); HttpURLConnection conn = (HttpURLConnection) u.openConnection
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025甲方支付委托合同书标准模板
- 2025城市绿化工程合同
- 2025顺丰快递转让合同样本
- 2025合法的合同劳动合同范本
- 2025套商业店铺转让合同模板
- 2025年食品级纤维素醚项目合作计划书
- 2025年连续玻璃纤维原丝毡项目建议书
- 2025年大型并网风力发电机组项目建议书
- 2025年新型膜材料及其装置合作协议书
- 2025年功能性棚模新材料及各种助剂项目合作计划书
- 2024届广东惠城区重点达标名校中考猜题语文试卷含解析
- MOOC 离散系统建模与仿真理论基础-南开大学 中国大学慕课答案
- 杜绝形式主义-从我做起
- 学生牛奶、糕点配送服务承诺及售后服务
- 卡通风幼儿园餐前播报
- 冷库制冷负荷计算表
- 迅雷网盘最最最全影视资源-持续更新7.26
- 中国先锋戏剧研究
- 南山区土地评估咨询报告
- 12、口腔科诊疗指南及技术操作规范
- 国有企业知识产权管理
评论
0/150
提交评论