public class HttpClient4Response extends SimpleWrapper<org.apache.http.HttpResponse> implements Response
CloseableHttpResponse
,实现获取响应状态码、响应头、响应体等内容raw
Constructor and Description |
---|
HttpClient4Response(org.apache.http.HttpResponse 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
|
HttpClient4Response |
sync()
同步
如果为异步状态,则暂时不读取服务器中响应的内容,而是持有Http链接的 InputStream 。 |
String |
toString() |
getRaw
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bodyBytes, contentEncoding, getCookieStr, getFileNameFromDisposition, header, headerList, isChunked, isOk, then
public HttpClient4Response(org.apache.http.HttpResponse rawRes, Request message)
rawRes
- HttpResponse
message
- 请求消息public int getStatus()
Response
public String header(String name)
Response
public Map<String,List<String>> headers()
Response
public long contentLength()
Response
contentLength
in interface Response
public InputStream bodyStream()
Response
bodyStream
in interface Response
public HttpClient4Response sync()
Response
InputStream
。public ResponseBody body()
Response
null
body
in interface Response
ResponseBody
public String bodyStr() throws HttpException
Response
bodyStr
in interface Response
HttpException
- 包装IO异常public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2025. All rights reserved.