public class RESTfulQuery {
/**
* businessDataQuery/{uniqueField}/{startTime}/{endTime}/{startNum}/{offset}/{businessType}/{appType}
*/
public static void main(String[] args) {
while(true){
queryCommonData();
}
}
/**
* 查询通用的RESTful接口
*/
public static void queryCommonData(){
String url = Constrants.BASEURL+" businessDataQuery/%s/%s/%s/%s/%s/%s/%s?format=json";
url = String.format(url,Constrants.PHONE,"2014-05-10","2014-06-11",0,0,"service","APP");
System.out.println(url);
HttpClient client = new HttpClient();
String responseString = null;
System.out.println(url);
GetMethod getM = null;
try {
getM = new GetMethod(url);
client.executeMethod(getM);
Reader reader = new InputStreamReader(
getM.getResponseBodyAsStream(), "utf8");
BufferedReader br = new BufferedReader(reader);
StringBuffer buf = new StringBuffer();
String line = "";
while (null != (line = br.readLine())) {
buf.append(line);
}
responseString = buf.toString();
System.out.println("\n");
System.out.println("\n"+responseString);
System.out.println();
} catch (Exception e) {
e.printStackTrace();
} finally {
getM.releaseConnection();
}
}
}
调用Restful接口方法的案例实战
猜你喜欢
转载自blog.csdn.net/Peter_Changyb/article/details/81564738
今日推荐
周排行