首页 > 编程语言 > 详细

java 调用接口事例

时间:2015-10-29 13:38:03      阅读:237      评论:0      收藏:0      [点我收藏+]

//调用接口

String inteFaceUrl = OperateProperties.readValueByKey("functionInteFace");

String strurl = inteFaceUrl+"/rest/bmwebservice/getreporthichar?towntype=1&type=1&datetype=1";

try {

HttpURLConnection con = null;//getSMSRecord

URL url = new URL(strurl);

con = (HttpURLConnection)url.openConnection();

con.setRequestMethod("POST");

con.setDoInput(true);

con.setDoOutput(true);

con.setUseCaches(false);

con.setRequestProperty("Accept","application/json");

con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");

DataOutputStream out = new DataOutputStream(con.getOutputStream());

out.flush();

out.close();

InputStreamReader input=new InputStreamReader(con.getInputStream(), "UTF-8");

BufferedReader bufReader = new BufferedReader(input);  

String line = "";  

StringBuilder contentBuf = new StringBuilder();  

while ((line = bufReader.readLine()) != null) {  

contentBuf.append(line);  

}

System.out.println(contentBuf.toString());

//处理数据

JSONObject json  = JSONObject.fromObject(contentBuf.toString());

JSONArray eventList = json.getJSONArray("data1");

data1=eventList.toString();

// request.setAttribute("data1", eventList.toString());

return "listreporthichar";

} catch (MalformedURLException e) {

e.printStackTrace();

} catch (ProtocolException e) {

e.printStackTrace();

} catch (UnsupportedEncodingException e) {

e.printStackTrace();

} catch (IOException e) {

e.printStackTrace();

}


java 调用接口事例

原文:http://my.oschina.net/u/2467394/blog/523459

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!