写个大概,上班再给你看看。
1、获取接口返回信息
StringBuffer sb = new StringBuffer("你的请求地址加参数");
URL url = new URL(sb.toString()); // 创建url对象
HttpURLConnection connection = (HttpURLConnection) url.openConnection(); // 打开url连接
connection.setRequestMethod("POST"); // 设置url请求方式 ‘get’ 或者 ‘post’
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); // 发送
// 返回发送结果
String inputline = "";
String tempStr = in.readLine();
while (tempStr != null) {
inputline = inputline + tempStr;
tempStr = in.readLine();
}
in.close();
return inputline;
2、解析接口信息(上班再些)
httpClient 抓取这个url地址的响应内容。取到xml字符串后,用dom4j解析