响应结果
| Constructor and description |
|---|
HttpClient.ResponseWrap
(org.apache.http.impl.client.CloseableHttpClient client, org.apache.http.client.methods.HttpRequestBase request, org.apache.http.client.methods.CloseableHttpResponse response, org.apache.http.client.protocol.HttpClientContext context) |
| Type | Name and description |
|---|---|
void |
abort()终止请求 |
boolean |
containsHeader(String name)是否存在指定 name 的 Header |
org.apache.http.Header[] |
getAllHeaders()获取所有 Header |
java.io.BufferedReader |
getBufferedReader()获取 BufferedReader |
byte[] |
getByteArray()获取响应内容为字节数组 |
java.nio.charset.Charset |
getCharset()获取响应编码,如果是文本的话 |
org.apache.http.Header |
getContentType()获取响应的类型 |
java.net.CookieStore |
getCookieStore()获取 CookieStore |
List<org.apache.http.cookie.Cookie> |
getCookies()获取 Cookie 列表 |
Map<String, String> |
getCookiesMap()获取转化成键值对的 Cookie |
org.apache.http.Header[] |
getHeaders(String name)获取知道名称的 Header 列表 |
java.io.InputStream |
getInputStream()获取 InputStream,需要手动关闭流 |
T |
getJson(Class<T> clazz = null, Map options = null)获取JSON对象 |
org.apache.http.ProtocolVersion |
getProtocolVersion()获取协议版本信息 |
List<java.net.URI> |
getRedirectLocations()获取重定向的地址 |
int |
getStatusCode()获得响应状态值,如 200、404 等。 |
org.apache.http.StatusLine |
getStatusLine()获取响应状态信息 @return |
String |
getString()获取响应内容为字符串,默认编码为 "UTF-8" |
String |
getString(java.nio.charset.Charset defaultCharset)获取响应内容为字符串 |
org.apache.http.HeaderIterator |
headerIterator()获取 Header 的迭代器 |
void |
removeHeader(org.apache.http.Header header)移除指定的 Header |
void |
removeHeader(String name, String value)移除指定的 Header |
void |
removeHeaders(String name)移除指定name的Header列表 |
ResponseWrap |
render(javax.servlet.http.HttpServletResponse resp)直接写入到浏览器的 http 响应中(类似于代理) |
void |
shutdown()关闭连接 |
void |
transferTo(String filePth)响应内容写入到文件 |
void |
transferTo(java.io.File file)响应内容写入到文件 |
void |
transferTo(java.io.OutputStream outputStream)写入到 OutputStream,并不会关闭 OutputStream |
| Methods inherited from class | Name |
|---|---|
class Object |
Object#wait(long, int), Object#wait(long), Object#wait(), Object#equals(Object), Object#toString(), Object#hashCode(), Object#getClass(), Object#notify(), Object#notifyAll() |
终止请求
是否存在指定 name 的 Header
获取所有 Header
获取 BufferedReader
获取响应内容为字节数组
获取响应编码,如果是文本的话
获取响应的类型
获取 CookieStore
获取 Cookie 列表
获取转化成键值对的 Cookie
获取知道名称的 Header 列表
获取 InputStream,需要手动关闭流
获取JSON对象
建议先对 getStatusCode() 进行校验,如果不是 200,则不执行,避免抛出 JSON 解析异常。
clazz - 转换后的类型options.dateFormat - 设置日期格式,默认为 "yyyy-MM-dd'T'HH:mm:ss.SSSZ"获取协议版本信息
获取重定向的地址
获得响应状态值,如 200、404 等。
获取响应状态信息
获取响应内容为字符串,默认编码为 "UTF-8"
如果抛出异常 java.lang.IllegalStateException: Content has not been provided,
可以调用 getStatusCode() 检查一下响应值,可能是 304 等其他值。
获取响应内容为字符串
defaultCharset - 指定编码获取 Header 的迭代器
移除指定的 Header
移除指定的 Header
移除指定name的Header列表
直接写入到浏览器的 http 响应中(类似于代理)
关闭连接
响应内容写入到文件
filePth - 路径响应内容写入到文件
写入到 OutputStream,并不会关闭 OutputStream
outputStream - OutputStreamBROPEN Documentation, 2020-04-21 10:53