本文主要来分享一下该工具类的测试结果。工具类的整体源码不再单独分享,源码基本上都已经在文章中了。开始我们的测试。
单线程调用测试:
public static void testOne() throws HttpProcessException{
System.out.println("--------简单方式调用(默认post)--------");
String url = "http://tool.oschina.net/";
//简单调用
String resp = HttpClientUtil.send(url);
System.out.println("请求结果内容长度:"+ resp.length());
System.out.println("\n#################################\n");
System.out.println("--------加入header设置--------");
url="http://blog.csdn.net/xiaoxian8023";
//设置header信息
Header[] headers=HttpHeader.custom().userAgent("Mozilla/5.0").build();
//执行请求
resp = HttpClientUtil.send(url, headers);
System.out.println("请求结果内容长度:"+ resp.length());
System.out.println("\n#################################\n");
System.out.println("--------代理设置(绕过证书验证)-------");
url="https://www.facebook.com/";
HttpClient client= HCB.custom().timeout(10000).proxy("127.0.0.1", 8087).ssl().build();//采用默认方式(绕过证书验证)
//执行请求
resp = HttpClientUtil.send(client,url);
System.out.println("请求结果内容长度:"+ resp.length());
System.out.println("\n#################################\n");
System.out.println("--------代理设置(自签名证书验证)+header+get方式-------");
url = "https://sso.tgb.com:8443/cas/login";
client= HCB.custom().timeout(10000).ssl("D:\\keys\\wsriakey","tomcat").build();
headers=HttpHeader.custom().keepAlive("false").connection("close").contentType(Headers.APP_FORM_URLENCODED).build();
//执行请求
resp