Most visited

Recently visited

Added in API level 11

WebResourceResponse

public class WebResourceResponse
extends Object

java.lang.Object
   ↳ android.webkit.WebResourceResponse


封装资源响应。 应用程序可以从shouldInterceptRequest(WebView, WebResourceRequest)返回此类的实例,以在WebView请求特定资源时提供自定义响应。

Summary

Public constructors

WebResourceResponse(String mimeType, String encoding, InputStream data)

使用给定的MIME类型,编码和输入流构造资源响应。

WebResourceResponse(String mimeType, String encoding, int statusCode, String reasonPhrase, Map<StringString> responseHeaders, InputStream data)

用给定的参数构造资源响应。

Public methods

InputStream getData()

获取提供资源响应数据的输入流。

String getEncoding()

获取资源响应的编码。

String getMimeType()

获取资源响应的MIME类型。

String getReasonPhrase()

获取资源响应状态码的描述。

Map<StringString> getResponseHeaders()

获取资源响应的标题。

int getStatusCode()

获取资源响应的状态码。

void setData(InputStream data)

设置提供资源响应数据的输入流。

void setEncoding(String encoding)

设置资源响应的编码,例如“UTF-8”。

void setMimeType(String mimeType)

设置资源响应的MIME类型,例如“text / html”。

void setResponseHeaders(Map<StringString> headers)

设置资源响应的标题。

void setStatusCodeAndReasonPhrase(int statusCode, String reasonPhrase)

设置资源响应的状态码和原因词组。

Inherited methods

From class java.lang.Object

Public constructors

WebResourceResponse

Added in API level 11
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

Added in API level 21
WebResourceResponse (String mimeType, 
                String encoding, 
                int statusCode, 
                String reasonPhrase, 
                Map<StringString> 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.

Public methods

getData

Added in API level 11
InputStream getData ()

获取提供资源响应数据的输入流。

Returns
InputStream The input stream that provides the resource response's data

getEncoding

Added in API level 11
String getEncoding ()

获取资源响应的编码。

Returns
String The resource response's encoding

getMimeType

Added in API level 11
String getMimeType ()

获取资源响应的MIME类型。

Returns
String The resource response's MIME type

getReasonPhrase

Added in API level 21
String getReasonPhrase ()

获取资源响应状态码的描述。

Returns
String The description of the resource response's status code.

getResponseHeaders

Added in API level 21
Map<StringString> getResponseHeaders ()

获取资源响应的标题。

Returns
Map<StringString> The headers for the resource response.

getStatusCode

Added in API level 21
int getStatusCode ()

获取资源响应的状态码。

Returns
int The resource response's status code.

setData

Added in API level 11
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.

setEncoding

Added in API level 11
void setEncoding (String encoding)

设置资源响应的编码,例如“UTF-8”。 这用于解码来自输入流的数据。

Parameters
encoding String: The resource response's encoding

setMimeType

Added in API level 11
void setMimeType (String mimeType)

设置资源响应的MIME类型,例如“text / html”。

Parameters
mimeType String: The resource response's MIME type

setResponseHeaders

Added in API level 21
void setResponseHeaders (Map<StringString> headers)

设置资源响应的标题。

Parameters
headers Map: Mapping of header name -> header value.

setStatusCodeAndReasonPhrase

Added in API level 21
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.

Hooray!