医院医生评价的java代码_基于JAVA的医院信息查询接口调用代码实例
基于JAVA的医院信息查询接口调用代码实例
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import net.sf.json.JSONObject;
/**
*医院信息调用示例代码 - 聚合数据
*在线接口文档:http://www.juhe.cn/docs/78
**/
public class JuheDemo {
public static final String DEF_CHATSET = "UTF-8";
public static final int DEF_CONN_TIMEOUT = 30000;
public static final int DEF_READ_TIMEOUT = 30000;
public static String userAgent = "Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.66 Safari/537.36";
//配置您申请的KEY
public static final String APPKEY ="*************************";
//1.医院信息查询
public static void getRequest1(){
String result =null;
String url ="http://op.juhe.cn/onebox/hospital/query";//请求接口地址
Mapparams = new HashMap();//请求参数
params.put("hospital","");//要查询的医院名称,如:苏州市立医院
params.put("key",APPKEY);//应用APPKEY(应用详细页查询)
params.put("dtype","");//返回数据的格式,xml或json,默认json
try {
result =net(url, params, "GET");
JSONObject object = JSONObject.fromObject(result);
if(object.getInt("error_code")==0){
System.out.println(object.get("result"));
}else{
System.out.println(object.get("error_code")+":"+object.get("reason"));
}
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
}
/**
*
* @param strUrl 请求地址
* @param params 请求参数
* @param method 请求方法
* @return 网络请求字符串
* @throws Exception
*/
public static String net(String strUrl, Mapparams,String method) throws Exception {
HttpURLConnection conn = null;
BufferedReader reader = null;
String rs = null;
try {
StringBuffer sb = new StringBuffer();
if(method==null || method.equals("GET")){
strUrl = strUrl+"?"+urlencode(params);
}
URL url = new URL(strUrl);
conn = (HttpURLConnection) url.openConnection();
if(method==null || method.equals("GET")){
conn.setRequestMethod("GET");
}else{
conn.setRequestMethod("POST");
conn.setDoOutput(true);
}
conn.setRequestProperty("User-agent", userAgent);
conn.setUseCaches(false);
conn.setConnectTimeout(DEF_CONN_TIMEOUT);
conn.setReadTimeout(DEF_READ_TIMEOUT);
conn.setInstanceFollowRedirects(false);
conn.connect();
if (params!= null && method.equals("POST")) {
try (DataOutputStream out = new DataOutputStream(conn.getOutputStream())) {
out.writeBytes(urlencode(params));
}
}
InputStream is = conn.getInputStream();
reader = new BufferedReader(new InputStreamReader(is, DEF_CHATSET));
String strRead = null;
while ((strRead = reader.readLine()) != null) {
sb.append(strRead);
}
rs = sb.toString();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
reader.close();
}
if (conn != null) {
conn.disconnect();
}
}
return rs;
}
//将map型转为请求参数型
public static String urlencode(Mapdata) {
StringBuilder sb = new StringBuilder();
for (Map.Entryi : data.entrySet()) {
try {
sb.append(i.getKey()).append("=").append(URLEncoder.encode(i.getValue()+"","UTF-8")).append("&");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return sb.toString();
}
}
医院医生评价的java代码_基于JAVA的医院信息查询接口调用代码实例相关推荐
- python在律师上作中的实例_基于Python的律师信息查询接口调用代码实例
基于Python的律师信息查询接口调用代码实例代码描述:基于Python的律师信息查询接口调用代码实例 代码平台:聚合数据 #!/usr/bin/python # -*- coding: utf-8 ...
- python个人信息查询代码_基于Python的商标信息查询api调用代码实例
#!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencode #-------- ...
- python的坐标代码_基于Python的地图坐标服务接口调用代码实例
代码描述:基于Python的地图坐标服务接口调用代码实例 关联数据:地图坐标服务 接口地址:http://www.juhe.cn/docs/api/id/32 #!/usr/bin/python # ...
- php如何获取手机序列号,基于php的苹果序列号查询接口调用代码实例
代码描述:基于php的苹果序列号查询接口调用代码实例 关联数据:苹果序列号 接口地址:http://www.juhe.cn/docs/api/id/37 // +------------------- ...
- python运势预测程序_基于Python的星座运势接口调用代码实例
[python]代码库#!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib import urlencod ...
- 名片识别信息分类python_基于Python的智能名片识别接口调用代码实例
基于Python的智能名片识别接口调用代码实例 #!/usr/bin/python # -*- coding: utf-8 -*- import json, urllib from urllib im ...
- php充值代码,基于php的加油卡充值接口调用代码实例
搜索热词 下面是编程之家 jb51.cc 通过网络收集整理的代码片段. 编程之家小编现在分享给大家,也给大家做个参考. 代码描述:基于PHP的加油卡充值接口调用代码实例 关联数据:加油卡充值 接口地址 ...
- 基于C#的全国天气查询API调用代码实例
全国天气查询API:https://www.juhe.cn/docs/api/id/39 基于C#的全国天气查询API调用代码实例 using System; using System.Collect ...
- Java毕业设计_基于SSM的医院预约挂号系统设计与实现
基于SSM的医院预约挂号系统设计与实现 基于SSM的医院预约挂号系统设计与实现mysql数据库创建语句 基于SSM的医院预约挂号系统设计与实现oracle数据库创建语句 基于SSM的医院预约挂号系统设 ...
最新文章
- Jmeter安装出现Not able to find Java executable or version问题解决方案
- VMWare虚拟机转换成KVM
- ABAP 标准培训教程 BC400 学习笔记之一:ABAP 服务器的架构和一个典型的 ABAP 程序结构介绍
- python标准库(一)
- Mysql数据库使用总结
- python中的封装调用_Python基础之封装
- 面试精讲之面试考点及大厂真题 - 分布式专栏 21 限流不能乱用-系统限流最佳实践
- bzoj4419 [Shoi2013]发微博 差分
- Kubernetes 配置私有镜像仓库时,没有权限访问的问题
- 父组件直接触发子组件中的函数
- Matlab绘制图像后在指定点绘制坐标线以及标注变量
- ArcSDE数据库学习总结
- c语言 多核优化,【模型工具】一种对SWMM5的多核优化
- 德·摩根定律的验证(De Morgan’s Laws)
- hao123首页源码 html,html css应用高仿hao123网站
- 21世纪十大热门编程语言大集合,看你适合哪一种?
- 出租权不适用于计算机软件,TRIPS协议下我国软件产业知识产权保护问题研究
- 数据库的行格式ROW_FORMAT
- 高通atheros ar93xx AP软件体系结构
- 小甲鱼python课后作业十三