Skip to content

Commit e6944ef

Browse files
author
Arronlong
authored
Merge pull request Arronlong#26 from Arronlong/develop
修改demo说明,同时更新版本到1.0.4
2 parents b4648cf + 25f73a5 commit e6944ef

4 files changed

Lines changed: 28 additions & 6 deletions

File tree

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<dependency>
99
<groupId>com.arronlong</groupId>
1010
<artifactId>httpclientutil</artifactId>
11-
<version>1.0.1</version>
11+
<version>1.0.4</version>
1212
</dependency>
1313
```
1414

@@ -75,7 +75,16 @@ public static void main(String[] args) throws HttpProcessException, FileNotFound
7575
//如果指向看是否访问正常
7676
//String result3 = HttpClientUtil.head(config); // 返回Http协议号+状态码
7777
//int statusCode = HttpClientUtil.status(config);//返回状态码
78-
78+
79+
//[新增方法]sendAndGetResp,可以返回原生的HttpResponse对象,
80+
//同时返回常用的几类对象:result、header、StatusLine、StatusCode
81+
HttpResult respResult = HttpClientUtil.sendAndGetResp(config);
82+
System.out.println("返回结果:\n"+respResult.getResult());
83+
System.out.println("返回resp-header:"+respResult.getRespHeaders());//可以遍历
84+
System.out.println("返回具体resp-header:"+respResult.getHeaders("Date"));
85+
System.out.println("返回StatusLine对象:"+respResult.getStatusLine());
86+
System.out.println("返回StatusCode:"+respResult.getStatusCode());
87+
System.out.println("返回HttpResponse对象)(可自行处理):"+respResult.getResp());
7988
}
8089
```
8190

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.arronlong</groupId>
55
<artifactId>httpclientutil</artifactId>
6-
<version>1.0.2</version>
6+
<version>1.0.4</version>
77
<name>${project.artifactId}</name>
88
<description>基于HttpClient-4.4.1封装的工具类。支持插件式配置Header、插件式配置httpclient对象,这样就可以方便地自定义header信息、配置ssl、配置proxy、Cookie等</description>
99

src/main/java/com/arronlong/httpclientutil/common/HttpResult.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public HttpResult(HttpResponse resp) {
5656
this.respHeaders = resp.getAllHeaders();
5757
this.protocolVersion = resp.getProtocolVersion();
5858
this.statusCode = resp.getStatusLine().getStatusCode();
59+
this.resp = resp;
5960
}
6061

6162
/**
@@ -64,8 +65,9 @@ public HttpResult(HttpResponse resp) {
6465
* @param name 头信息名称
6566
* @return
6667
*/
67-
public Header[] getHeaders(final String name) {
68-
return this.resp.getHeaders(name);
68+
public Header getHeaders(final String name) {
69+
Header[] headers = this.resp.getHeaders(name);
70+
return headers!=null && headers.length>0?headers[0]:null;
6971
}
7072

7173
public String getResult() {

src/test/java/com/arronlong/httpclientutil/test/Demo.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import com.arronlong.httpclientutil.builder.HCB;
1212
import com.arronlong.httpclientutil.common.HttpConfig;
1313
import com.arronlong.httpclientutil.common.HttpHeader;
14+
import com.arronlong.httpclientutil.common.HttpResult;
1415
import com.arronlong.httpclientutil.common.SSLs.SSLProtocolVersion;
1516
import com.arronlong.httpclientutil.exception.HttpProcessException;
1617

@@ -84,6 +85,16 @@ public static void main(String[] args) throws HttpProcessException, FileNotFound
8485
//如果指向看是否访问正常
8586
//String result3 = HttpClientUtil.head(config); // 返回Http协议号+状态码
8687
//int statusCode = HttpClientUtil.status(config);//返回状态码
87-
88+
89+
//[新增方法]sendAndGetResp,可以返回原生的HttpResponse对象,
90+
//同时返回常用的几类对象:result、header、StatusLine、StatusCode
91+
HttpResult respResult = HttpClientUtil.sendAndGetResp(config);
92+
System.out.println("返回结果:\n"+respResult.getResult());
93+
System.out.println("返回resp-header:"+respResult.getRespHeaders());//可以遍历
94+
System.out.println("返回具体resp-header:"+respResult.getHeaders("Date"));
95+
System.out.println("返回StatusLine对象:"+respResult.getStatusLine());
96+
System.out.println("返回StatusCode:"+respResult.getStatusCode());
97+
System.out.println("返回HttpResponse对象)(可自行处理):"+respResult.getResp());
98+
8899
}
89100
}

0 commit comments

Comments
 (0)