# WebResourceResponse

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Ctors](https://developer.android.com/reference/android/webkit/WebResourceResponse#pubctors)\|[Methods](https://developer.android.com/reference/android/webkit/WebResourceResponse#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/webkit/WebResourceResponse#inhmethods)  

# WebResourceResponse

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/webkit/WebResourceResponse "View this page in Kotlin")\|Java

`
public


class
WebResourceResponse
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.webkit.WebResourceResponse |

<br />

*** ** * ** ***

Encapsulates a resource response. Applications can return an instance of this class from[WebViewClient.shouldInterceptRequest](https://developer.android.com/reference/android/webkit/WebViewClient#shouldInterceptRequest(android.webkit.WebView,%20android.webkit.WebResourceRequest))to provide a custom response when the WebView requests a particular resource.

## Summary

|                                                                                                                                                                                                                                                                                                                                                                                                                                               ### Public constructors                                                                                                                                                                                                                                                                                                                                                                                                                                                ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse#WebResourceResponse(java.lang.String,%20java.lang.String,%20int,%20java.lang.String,%20java.util.Map<java.lang.String,java.lang.String>,%20java.io.InputStream))`(`[String](https://developer.android.com/reference/java/lang/String)` mimeType, `[String](https://developer.android.com/reference/java/lang/String)` encoding, int statusCode, `[String](https://developer.android.com/reference/java/lang/String)` reasonPhrase, `[Map](https://developer.android.com/reference/java/util/Map)`<`[String](https://developer.android.com/reference/java/lang/String)`, `[String](https://developer.android.com/reference/java/lang/String)`> responseHeaders, `[InputStream](https://developer.android.com/reference/java/io/InputStream)` data) ` Constructs a resource response with the given parameters. |
| ` `[WebResourceResponse](https://developer.android.com/reference/android/webkit/WebResourceResponse#WebResourceResponse(java.lang.String,%20java.lang.String,%20java.io.InputStream))`(`[String](https://developer.android.com/reference/java/lang/String)` mimeType, `[String](https://developer.android.com/reference/java/lang/String)` encoding, `[InputStream](https://developer.android.com/reference/java/io/InputStream)` data) ` Constructs a resource response with the given MIME type, character encoding, and input stream.                                                                                                                                                                                                                                                                                                                                                                          |

|                                                                                                                                                                                                                                                                                                                     ### Public methods                                                                                                                                                                                                                                                                                                                     ||
|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[InputStream](https://developer.android.com/reference/java/io/InputStream)                                                                                                                                 | ` `[getData](https://developer.android.com/reference/android/webkit/WebResourceResponse#getData())`() ` Gets the input stream that provides the resource response's data.                                                                                                                                                                                                                                                                   |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                                                                                                                         | ` `[getEncoding](https://developer.android.com/reference/android/webkit/WebResourceResponse#getEncoding())`() ` Gets the resource response's encoding.                                                                                                                                                                                                                                                                                      |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                                                                                                                         | ` `[getMimeType](https://developer.android.com/reference/android/webkit/WebResourceResponse#getMimeType())`() ` Gets the resource response's MIME type.                                                                                                                                                                                                                                                                                     |
| ` `[String](https://developer.android.com/reference/java/lang/String)                                                                                                                                         | ` `[getReasonPhrase](https://developer.android.com/reference/android/webkit/WebResourceResponse#getReasonPhrase())`() ` Gets the description of the resource response's status code.                                                                                                                                                                                                                                                        |
| ` `[Map](https://developer.android.com/reference/java/util/Map)`<`[String](https://developer.android.com/reference/java/lang/String)`, `[String](https://developer.android.com/reference/java/lang/String)`>` | ` `[getResponseHeaders](https://developer.android.com/reference/android/webkit/WebResourceResponse#getResponseHeaders())`() ` Gets the headers for the resource response.                                                                                                                                                                                                                                                                   |
| ` int`                                                                                                                                                                                                        | ` `[getStatusCode](https://developer.android.com/reference/android/webkit/WebResourceResponse#getStatusCode())`() ` Gets the resource response's status code.                                                                                                                                                                                                                                                                               |
| ` void`                                                                                                                                                                                                       | ` `[setData](https://developer.android.com/reference/android/webkit/WebResourceResponse#setData(java.io.InputStream))`(`[InputStream](https://developer.android.com/reference/java/io/InputStream)` data) ` Sets the input stream that provides the resource response's data.                                                                                                                                                               |
| ` void`                                                                                                                                                                                                       | ` `[setEncoding](https://developer.android.com/reference/android/webkit/WebResourceResponse#setEncoding(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` encoding) ` Sets the resource response's encoding, for example "UTF-8".                                                                                                                                                                    |
| ` void`                                                                                                                                                                                                       | ` `[setMimeType](https://developer.android.com/reference/android/webkit/WebResourceResponse#setMimeType(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` mimeType) ` Sets the resource response's MIME type, for example "text/html".                                                                                                                                                               |
| ` void`                                                                                                                                                                                                       | ` `[setResponseHeaders](https://developer.android.com/reference/android/webkit/WebResourceResponse#setResponseHeaders(java.util.Map<java.lang.String,java.lang.String>))`(`[Map](https://developer.android.com/reference/java/util/Map)`<`[String](https://developer.android.com/reference/java/lang/String)`, `[String](https://developer.android.com/reference/java/lang/String)`> headers) ` Sets the headers for the resource response. |
| ` void`                                                                                                                                                                                                       | ` `[setStatusCodeAndReasonPhrase](https://developer.android.com/reference/android/webkit/WebResourceResponse#setStatusCodeAndReasonPhrase(int,%20java.lang.String))`(int statusCode, `[String](https://developer.android.com/reference/java/lang/String)` reasonPhrase) ` Sets the resource response's status code and reason phrase.                                                                                                       |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Public constructors

### WebResourceResponse

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

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

Constructs a resource response with the given parameters. Callers must implement[InputStream.read(byte[])](https://developer.android.com/reference/java/io/InputStream#read(byte[]))for the input stream.[InputStream.close()](https://developer.android.com/reference/java/io/InputStream#close())will be called after the WebView has finished with the response.

**Note:** See[WebResourceResponse(java.lang.String, java.lang.String, java.io.InputStream)](https://developer.android.com/reference/android/webkit/WebResourceResponse#WebResourceResponse(java.lang.String,%20java.lang.String,%20java.io.InputStream))for details on what should be specified for`mimeType`and`encoding`.

<br />

|                                                                              Parameters                                                                              ||
|-------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `mimeType`        | `String`: the resource response's MIME type, for example`"text/html"`. <br />                                                                     |
| `encoding`        | `String`: the resource response's character encoding, for example`"utf-8"`. <br />                                                                |
| `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. <br /> |
| `reasonPhrase`    | `String`: the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be`null`. <br />                          |
| `responseHeaders` | `Map`: the resource response's headers represented as a mapping of header name -\> header value. <br />                                           |
| `data`            | `InputStream`: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. <br />                         |

### WebResourceResponse

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public WebResourceResponse (String mimeType, 
                String encoding, 
                InputStream data)
```

Constructs a resource response with the given MIME type, character encoding, and input stream. Callers must implement[InputStream.read(byte[])](https://developer.android.com/reference/java/io/InputStream#read(byte[]))for the input stream.[InputStream.close()](https://developer.android.com/reference/java/io/InputStream#close())will be called after the WebView has finished with the response.

**Note:** The MIME type and character encoding must be specified as separate parameters (for example`"text/html"`and`"utf-8"`), not a single value like the`"text/html; charset=utf-8"`format used in the HTTP Content-Type header. Do not use the value of a HTTP Content-Encoding header for`encoding`, as that header does not specify a character encoding. Content without a defined character encoding (for example image resources) should pass`null`for`encoding`.

<br />

|                                                              Parameters                                                               ||
|------------|---------------------------------------------------------------------------------------------------------------------------|
| `mimeType` | `String`: the resource response's MIME type, for example`"text/html"`. <br />                                             |
| `encoding` | `String`: the resource response's character encoding, for example`"utf-8"`. <br />                                        |
| `data`     | `InputStream`: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. <br /> |

## Public methods

### getData

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public InputStream getData ()
```

Gets the input stream that provides the resource response's data.

<br />

|                                                                    Returns                                                                     ||
|----------------------------------------------------------------------------|--------------------------------------------------------------------|
| [InputStream](https://developer.android.com/reference/java/io/InputStream) | The input stream that provides the resource response's data <br /> |

### getEncoding

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getEncoding ()
```

Gets the resource response's encoding.

<br />

|                                                   Returns                                                   ||
|--------------------------------------------------------------------|-----------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | The resource response's encoding <br /> |

### getMimeType

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getMimeType ()
```

Gets the resource response's MIME type.

<br />

|                                                   Returns                                                    ||
|--------------------------------------------------------------------|------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | The resource response's MIME type <br /> |

### getReasonPhrase

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public String getReasonPhrase ()
```

Gets the description of the resource response's status code.

<br />

|                                                              Returns                                                               ||
|--------------------------------------------------------------------|----------------------------------------------------------------|
| [String](https://developer.android.com/reference/java/lang/String) | The description of the resource response's status code. <br /> |

### getResponseHeaders

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public Map<String, String> getResponseHeaders ()
```

Gets the headers for the resource response.

<br />

|                                                                                                                          Returns                                                                                                                          ||
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------|
| [Map](https://developer.android.com/reference/java/util/Map)`<`[String](https://developer.android.com/reference/java/lang/String)`, `[String](https://developer.android.com/reference/java/lang/String)`>` | The headers for the resource response. <br /> |

### getStatusCode

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public int getStatusCode ()
```

Gets the resource response's status code.

<br />

|                      Returns                       ||
|-------|---------------------------------------------|
| `int` | The resource response's status code. <br /> |

### setData

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setData (InputStream data)
```

Sets the input stream that provides the resource response's data. Callers must implement[InputStream.read(byte[])](https://developer.android.com/reference/java/io/InputStream#read(byte[])).[InputStream.close()](https://developer.android.com/reference/java/io/InputStream#close())will be called after the WebView has finished with the response.

<br />

|                                                            Parameters                                                             ||
|--------|---------------------------------------------------------------------------------------------------------------------------|
| `data` | `InputStream`: the input stream that provides the resource response's data. Must not be a StringBufferInputStream. <br /> |

### setEncoding

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setEncoding (String encoding)
```

Sets the resource response's encoding, for example "UTF-8". This is used to decode the data from the input stream.

<br />

|                          Parameters                           ||
|------------|---------------------------------------------------|
| `encoding` | `String`: The resource response's encoding <br /> |

### setMimeType

Added in[API level 11](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setMimeType (String mimeType)
```

Sets the resource response's MIME type, for example "text/html".

<br />

|                           Parameters                           ||
|------------|----------------------------------------------------|
| `mimeType` | `String`: The resource response's MIME type <br /> |

### setResponseHeaders

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setResponseHeaders (Map<String, String> headers)
```

Sets the headers for the resource response.

<br />

|                            Parameters                             ||
|-----------|--------------------------------------------------------|
| `headers` | `Map`: Mapping of header name -\> header value. <br /> |

### setStatusCodeAndReasonPhrase

Added in[API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setStatusCodeAndReasonPhrase (int statusCode, 
                String reasonPhrase)
```

Sets the resource response's status code and reason phrase.

<br />

|                                                                            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. <br /> |
| `reasonPhrase` | `String`: the phrase describing the status code, for example "OK". Must be non-empty. This value cannot be`null`. <br />                          |