public class RawResponse extends Object implements AutoCloseable
| 限定符和类型 | 字段和说明 |
|---|---|
protected List<Cookie> |
cookies |
protected Headers |
headers |
protected int |
statusCode |
protected String |
url |
| 构造器和说明 |
|---|
RawResponse(String method,
String url,
int statusCode,
String statusLine,
List<Cookie> cookies,
Headers headers,
InputStream body,
Charset charset,
boolean decompress) |
RawResponse(String method,
String url,
int statusCode,
String statusLine,
List<Cookie> cookies,
Headers headers,
InputStream input,
HttpURLConnection conn) |
| 限定符和类型 | 方法和说明 |
|---|---|
InputStream |
body()
The response body input stream
|
@Nullable Charset |
charset() |
RawResponse |
charset(Charset charset)
Set response read charset.
|
RawResponse |
charset(String charset)
Set response read charset.
|
void |
close() |
List<Cookie> |
cookies()
Get all cookies returned by this response
|
boolean |
decompress() |
RawResponse |
decompress(boolean decompress)
If decompress http response body.
|
void |
discardBody()
Consume and discard this response body.
|
@Nullable Cookie |
getCookie(String name)
Get first cookie match the name returned by this response, return null if not found
|
List<Cookie> |
getCookies()
已过时。
using
cookies |
@Nullable Cookie |
getFirstCookie(String name)
已过时。
using {
getCookie(String)} instead |
@Nullable String |
getFirstHeader(String name)
已过时。
using
getHeader(String) instead |
@Nullable String |
getHeader(String name)
Get first header value match the name, return null if not exists
|
List<Header> |
getHeaders()
已过时。
using
headers |
List<String> |
getHeaders(String name)
Get all headers values with name.
|
InputStream |
getInput()
已过时。
use
body() |
int |
getStatusCode()
已过时。
using
statusCode |
String |
getStatusLine()
已过时。
use
statusLine() |
String |
getURL()
已过时。
using
url |
List<Header> |
headers()
Return all response headers
|
String |
method() |
byte[] |
readToBytes()
Read response body to byte array. return empty byte array if response has no body
|
<T> T |
readToJson(Class<T> cls)
Deserialize response content as json
|
<T> T |
readToJson(Type type)
Deserialize response content as json
|
<T> T |
readToJson(TypeInfer<T> typeInfer)
Deserialize response content as json
|
String |
readToText()
Read response body to string. return empty string if response has no body
|
int |
statusCode()
return response status code
|
String |
statusLine()
Get the status line
|
Response<byte[]> |
toBytesResponse()
Convert to response, with body as byte array
|
Response<File> |
toFileResponse(Path path)
Write response body to file, and return response contains the file.
|
<T> Response<T> |
toJsonResponse(Class<T> cls)
Convert http response body to json result
|
<T> Response<T> |
toJsonResponse(TypeInfer<T> typeInfer)
Convert http response body to json result
|
<T> Response<T> |
toResponse(ResponseHandler<T> handler)
Handle response body with handler, return a new response with content as handler result.
|
Response<String> |
toTextResponse()
Convert to response, with body as text.
|
String |
url()
return actual url (redirected)
|
RawResponse |
withCharset(Charset charset)
已过时。
use {
charset(Charset)} instead |
void |
writeTo(OutputStream out)
Write response body to OutputStream.
|
void |
writeTo(Writer writer)
Write response body to Writer, charset can be set using
charset(Charset),
or will use charset detected from response header if not set. |
void |
writeToFile(File file)
Write response body to file
|
void |
writeToFile(Path path)
Write response body to file
|
void |
writeToFile(String path)
Write response body to file
|
protected final String url
protected final int statusCode
protected final Headers headers
public RawResponse(String method, String url, int statusCode, String statusLine, List<Cookie> cookies, Headers headers, InputStream body, Charset charset, boolean decompress)
public RawResponse(String method, String url, int statusCode, String statusLine, List<Cookie> cookies, Headers headers, InputStream input, HttpURLConnection conn)
public void close()
close 在接口中 AutoCloseable@Deprecated public RawResponse withCharset(Charset charset)
charset(Charset)} insteadpublic RawResponse charset(Charset charset)
public RawResponse charset(String charset)
public RawResponse decompress(boolean decompress)
public String readToText()
public Response<String> toTextResponse()
public byte[] readToBytes()
public <T> Response<T> toResponse(ResponseHandler<T> handler)
public Response<byte[]> toBytesResponse()
public <T> T readToJson(Type type)
public <T> T readToJson(TypeInfer<T> typeInfer)
public <T> T readToJson(Class<T> cls)
public <T> Response<T> toJsonResponse(TypeInfer<T> typeInfer)
public <T> Response<T> toJsonResponse(Class<T> cls)
public void writeToFile(File file)
public void writeToFile(Path path)
public void writeToFile(String path)
public Response<File> toFileResponse(Path path)
public void writeTo(OutputStream out)
public void writeTo(Writer writer)
charset(Charset),
or will use charset detected from response header if not set.
Writer will not be closed.public void discardBody()
@Deprecated public String getStatusLine()
statusLine()public String statusLine()
@Deprecated public InputStream getInput()
body()public String method()
public InputStream body()
public @Nullable Charset charset()
public boolean decompress()
@Deprecated public String getURL()
urlpublic String url()
@Deprecated public int getStatusCode()
statusCodepublic int statusCode()
@Deprecated public List<Cookie> getCookies()
cookies@Deprecated public List<Header> getHeaders()
headers@Deprecated public @Nullable Cookie getFirstCookie(String name)
getCookie(String)} insteadpublic @Nullable Cookie getCookie(String name)
@Deprecated public @Nullable String getFirstHeader(String name)
getHeader(String) insteadpublic @Nullable String getHeader(String name)
Copyright © 2019. All rights reserved.