public class HttpClient5Response extends SimpleWrapper<org.apache.hc.core5.http.ClassicHttpResponse> implements Response
CloseableHttpResponse,实现获取响应状态码、响应头、响应体等内容raw| Constructor and Description |
|---|
HttpClient5Response(org.apache.hc.core5.http.ClassicHttpResponse rawRes,
Request message)
构造
通过传入一个请求时的编码,当无法获取响应内容的编码时,默认使用响应时的编码 |
| Modifier and Type | Method and Description |
|---|---|
ResponseBody |
body()
获取响应体,包含服务端返回的内容和Content-Type信息
如果为HEAD、CONNECT、TRACE等方法无响应体,则返回 null |
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
|
HttpClient5Response |
sync()
同步
如果为异步状态,则暂时不读取服务器中响应的内容,而是持有Http链接的 InputStream。 |
String |
toString() |
getRawclone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitbodyBytes, contentEncoding, getCookieStr, getFileNameFromDisposition, header, headerList, isChunked, isOk, thenpublic HttpClient5Response(org.apache.hc.core5.http.ClassicHttpResponse rawRes,
Request message)
rawRes - CloseableHttpResponsemessage - 请求消息public int getStatus()
Responsepublic String header(String name)
Responsepublic Map<String,List<String>> headers()
Responsepublic long contentLength()
ResponsecontentLength in interface Responsepublic InputStream bodyStream()
ResponsebodyStream in interface Responsepublic HttpClient5Response sync()
ResponseInputStream。public ResponseBody body()
Responsenullbody in interface ResponseResponseBodypublic String bodyStr() throws HttpException
ResponsebodyStr in interface ResponseHttpException - 包装IO异常public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2025. All rights reserved.