public class WebResourceResponse
extends Object
| java.lang.Object | |
| android.webkit.WebResourceResponse | |
封装资源响应。 应用程序可以从shouldInterceptRequest(WebView, WebResourceRequest)返回此类的实例,以在WebView请求特定资源时提供自定义响应。
Public constructors |
|
|---|---|
WebResourceResponse(String mimeType, String encoding, InputStream data) 使用给定的MIME类型,编码和输入流构造资源响应。 |
|
WebResourceResponse(String mimeType, String encoding, int statusCode, String reasonPhrase, Map<String, String> responseHeaders, InputStream data) 用给定的参数构造资源响应。 |
|
公共方法(Public methods) |
|
|---|---|
InputStream |
getData() 获取提供资源响应数据的输入流。 |
String |
getEncoding() 获取资源响应的编码。 |
String |
getMimeType() 获取资源响应的MIME类型。 |
String |
getReasonPhrase() 获取资源响应状态码的描述。 |
Map<String, String> |
getResponseHeaders() 获取资源响应的标题。 |
int |
getStatusCode() 获取资源响应的状态码。 |
void |
setData(InputStream data) 设置提供资源响应数据的输入流。 |
void |
setEncoding(String encoding) 设置资源响应的编码,例如“UTF-8”。 |
void |
setMimeType(String mimeType) 设置资源响应的MIME类型,例如“text / html”。 |
void |
setResponseHeaders(Map<String, String> headers) 设置资源响应的标题。 |
void |
setStatusCodeAndReasonPhrase(int statusCode, String reasonPhrase) 设置资源响应的状态码和原因词组。 |
继承方法(Inherited methods) |
|
|---|---|
java.lang.Object
|
|
WebResourceResponse (String mimeType, String encoding, InputStream data)
使用给定的MIME类型,编码和输入流构造资源响应。 呼叫者必须为输入流实现InputStream.read(byte[]) 。
| 参数(Parameters) | |
|---|---|
mimeType |
String: the resource response's MIME type, for example text/html |
encoding |
String: the resource response's encoding |
data |
InputStream: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
WebResourceResponse (String mimeType, String encoding, int statusCode, String reasonPhrase, Map<String, String> responseHeaders, InputStream data)
用给定的参数构造资源响应。 呼叫者必须为输入流实现InputStream.read(byte[]) 。
| 参数(Parameters) | |
|---|---|
mimeType |
String: the resource response's MIME type, for example text/html |
encoding |
String: the resource response's encoding |
statusCode |
int: the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported. |
reasonPhrase |
String: the phrase describing the status code, for example "OK". Must be non-null and not empty. |
responseHeaders |
Map: the resource response's headers represented as a mapping of header name -> header value. |
data |
InputStream: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
InputStream getData ()
获取提供资源响应数据的输入流。
| 返回(Returns) | |
|---|---|
InputStream |
The input stream that provides the resource response's data |
String getEncoding ()
获取资源响应的编码。
| 返回(Returns) | |
|---|---|
String |
The resource response's encoding |
String getMimeType ()
获取资源响应的MIME类型。
| 返回(Returns) | |
|---|---|
String |
The resource response's MIME type |
String getReasonPhrase ()
获取资源响应状态码的描述。
| 返回(Returns) | |
|---|---|
String |
The description of the resource response's status code. |
Map<String, String> getResponseHeaders ()
获取资源响应的标题。
| 返回(Returns) | |
|---|---|
Map<String, String> |
The headers for the resource response. |
int getStatusCode ()
获取资源响应的状态码。
| 返回(Returns) | |
|---|---|
int |
The resource response's status code. |
void setData (InputStream data)
设置提供资源响应数据的输入流。 呼叫者必须执行InputStream.read(byte[]) 。
| 参数(Parameters) | |
|---|---|
data |
InputStream: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. |
void setEncoding (String encoding)
设置资源响应的编码,例如“UTF-8”。 这用于解码来自输入流的数据。
| 参数(Parameters) | |
|---|---|
encoding |
String: The resource response's encoding |
void setMimeType (String mimeType)
设置资源响应的MIME类型,例如“text / html”。
| 参数(Parameters) | |
|---|---|
mimeType |
String: The resource response's MIME type |
void setResponseHeaders (Map<String, String> headers)
设置资源响应的标题。
| 参数(Parameters) | |
|---|---|
headers |
Map: Mapping of header name -> header value. |
void setStatusCodeAndReasonPhrase (int statusCode,
String reasonPhrase)
设置资源响应的状态码和原因词组。
| 参数(Parameters) | |
|---|---|
statusCode |
int: the status code needs to be in the ranges [100, 299], [400, 599]. Causing a redirect by specifying a 3xx code is not supported. |
reasonPhrase |
String: the phrase describing the status code, for example "OK". Must be non-null and not empty. |