Java类:team.bangbang.common.net.http.HttpClient

使用OkHttp封装实现,可以同步或者异步调用Http服务,详情参见Java doc文档。

使用示例

// server
HttpClient hc = new HttpClient();

// 地址
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=";

long l1 = System.currentTimeMillis();
ResponseHandler rh = hc.get(url);
System.out.print(" 返回内容是: " + content);
long l2 = System.currentTimeMillis();
// 返回内容,转换为JSON
JSONObject content = rh.toJSONObject();
System.out.print("返回内容 : " + content);
System.out.print("用时: " + (l2 - l1) + " ms");