public class OkHttpResponse extends Object implements Response
Response
响应包装Constructor and Description |
---|
OkHttpResponse(okhttp3.Response rawRes,
Request message) |
Modifier and Type | Method and Description |
---|---|
ResponseBody |
body()
获取响应体,包含服务端返回的内容和Content-Type信息
如果为HEAD、CONNECT、TRACE等方法无响应体,则返回 null |
InputStream |
bodyStream()
获得服务区响应流
流获取后处理完毕需关闭此类 |
Charset |
charset()
获取字符集编码,默认为响应头中的编码
|
void |
close() |
int |
getStatus()
获取状态码
|
String |
header(String name)
根据name获取头信息
根据RFC2616规范,header的name不区分大小写 |
Map<String,List<String>> |
headers()
获取headers
|
OkHttpResponse |
sync()
同步
如果为异步状态,则暂时不读取服务器中响应的内容,而是持有Http链接的 InputStream 。 |
String |
toString() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
bodyBytes, bodyStr, contentEncoding, contentLength, getCookieStr, getFileNameFromDisposition, header, headerList, isChunked, isOk, then
public OkHttpResponse(okhttp3.Response rawRes, Request message)
rawRes
- Response
message
- 请求对象public int getStatus()
Response
public String header(String name)
Response
public Map<String,List<String>> headers()
Response
public InputStream bodyStream()
Response
bodyStream
in interface Response
public OkHttpResponse sync()
Response
InputStream
。public ResponseBody body()
Response
null
body
in interface Response
ResponseBody
public void close()
close
in interface Closeable
close
in interface AutoCloseable
Copyright © 2025. All rights reserved.