public class HttpClient5Response extends Object implements Response
CloseableHttpResponse,实现获取响应状态码、响应头、响应体等内容| 构造器和说明 |
|---|
HttpClient5Response(org.apache.hc.core5.http.ClassicHttpResponse rawRes,
Charset requestCharset)
构造
通过传入一个请求时的编码,当无法获取响应内容的编码时,默认使用响应时的编码 |
| 限定符和类型 | 方法和说明 |
|---|---|
String |
bodyStr()
获取响应主体
|
InputStream |
bodyStream()
获得服务区响应流
流获取后处理完毕需关闭此类 |
Charset |
charset()
获取字符集编码,默认为响应头中的编码
|
void |
close() |
long |
contentLength()
获取内容长度,以下情况长度无效:
Transfer-Encoding: Chunked
Content-Encoding: XXX
参考:https://blog.csdn.net/jiang7701037/article/details/86304302
|
int |
getStatus()
获取状态码
|
String |
header(String name)
根据name获取头信息
根据RFC2616规范,header的name不区分大小写 |
Map<String,List<String>> |
headers()
获取headers
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitbody, bodyBytes, contentEncoding, getCookieStr, header, isChunked, isOk, thenpublic HttpClient5Response(org.apache.hc.core5.http.ClassicHttpResponse rawRes,
Charset requestCharset)
rawRes - CloseableHttpResponserequestCharset - 请求时的编码public String header(String name)
Responsepublic long contentLength()
ResponsecontentLength 在接口中 Responsepublic InputStream bodyStream()
ResponsebodyStream 在接口中 Responsepublic String bodyStr() throws HttpException
ResponsebodyStr 在接口中 ResponseHttpException - 包装IO异常public void close()
throws IOException
close 在接口中 Closeableclose 在接口中 AutoCloseableIOExceptionCopyright © 2023. All rights reserved.