• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Class (WebResourceResponse)
2
3Implements the **WebResourceResponse** object. For details about the sample code, see [onHttpErrorReceive](./arkts-basic-components-web-events.md#onhttperrorreceive).
4
5> **NOTE**
6>
7> - The initial APIs of this component are supported since API version 8. Updates will be marked with a superscript to indicate their earliest API version.
8>
9> - The initial APIs of this class are supported since API version 8.
10>
11> - You can preview how this component looks on a real device, but not in DevEco Studio Previewer.
12
13## constructor
14
15constructor()
16
17Constructs a **WebResourceResponse**.
18
19**System capability**: SystemCapability.Web.Webview.Core
20
21## getReasonMessage
22
23getReasonMessage(): string
24
25Obtains the status code description of the resource response.
26
27**System capability**: SystemCapability.Web.Webview.Core
28
29**Return value**
30
31| Type    | Description           |
32| ------ | ------------- |
33| string | Status code description of the resource response.|
34
35## getResponseCode
36
37getResponseCode(): number
38
39Obtains the status code of the resource response.
40
41**System capability**: SystemCapability.Web.Webview.Core
42
43**Return value**
44
45| Type    | Description         |
46| ------ | ----------- |
47| number | Status code of the resource response.|
48
49## getResponseData
50
51getResponseData(): string
52
53Obtains the data in the resource response.
54
55**System capability**: SystemCapability.Web.Webview.Core
56
57**Return value**
58
59| Type    | Description       |
60| ------ | --------- |
61| string | Data in the resource response.|
62
63## getResponseEncoding
64
65getResponseEncoding(): string
66
67Obtains the encoding string of the resource response.
68
69**System capability**: SystemCapability.Web.Webview.Core
70
71**Return value**
72
73| Type    | Description        |
74| ------ | ---------- |
75| string | Encoding string of the resource response.|
76
77## getResponseHeader
78
79getResponseHeader() : Array\<Header\>
80
81Obtains the resource response header.
82
83**System capability**: SystemCapability.Web.Webview.Core
84
85**Return value**
86
87| Type                        | Description      |
88| -------------------------- | -------- |
89| Array\<[Header](./arkts-basic-components-web-i.md#header)\> | Resource response header.|
90
91## getResponseMimeType
92
93getResponseMimeType(): string
94
95Obtains the MIME type of the resource response.
96
97**System capability**: SystemCapability.Web.Webview.Core
98
99**Return value**
100
101| Type    | Description                |
102| ------ | ------------------ |
103| string | MIME type of the resource response.|
104
105## getResponseDataEx<sup>13+</sup>
106
107getResponseDataEx(): string | number | ArrayBuffer | Resource | undefined
108
109Obtains the data in the resource response. Multiple data types are supported.
110
111**System capability**: SystemCapability.Web.Webview.Core
112
113**Return value**
114
115|Type|Description|
116|---|---|
117|string|String in HTML format.|
118|number|Handle to the file.|
119|ArrayBuffer|Binary data.|
120|[Resource](../apis-arkui/arkui-ts/ts-types.md#resource)|Resource referenced by **$rawfile()**.|
121|undefined|No available data.|
122
123## getResponseIsReady<sup>13+</sup>
124
125getResponseIsReady(): boolean
126
127Obtains whether the response data is ready.
128
129**System capability**: SystemCapability.Web.Webview.Core
130
131**Return value**
132
133|Type|Description|
134|---|---|
135|boolean|**true** indicates that the response data is ready, and **false** indicates the opposite.|
136
137## setResponseData<sup>9+</sup>
138
139setResponseData(data: string \| number \| Resource \| ArrayBuffer): void
140
141Sets the data in the resource response.
142
143**System capability**: SystemCapability.Web.Webview.Core
144
145**Parameters**
146
147| Name | Type                                    | Mandatory  | Description                                    |
148| ---- | ---------------------------------------- | ---- | ---------------------------------------- |
149| data | string \| number \| [Resource](../apis-arkui/arkui-ts/ts-types.md#resource)<sup>10+</sup> \| ArrayBuffer<sup>11+</sup> | Yes   | Resource response data to set. When set to a string, the value indicates a string in HTML format. When set to a number, the value indicates a file handle, which is closed by the system **Web** component. When set to a **Resource** object, the value indicates the file resources in the **rawfile** directory of the application. When set to an **ArrayBuffer** object, the value indicates the original binary data of a resource.|
150
151## setResponseEncoding<sup>9+</sup>
152
153setResponseEncoding(encoding: string): void
154
155Sets the encoding string of the resource response.
156
157**System capability**: SystemCapability.Web.Webview.Core
158
159**Parameters**
160
161| Name     | Type  | Mandatory  | Description        |
162| -------- | ------ | ---- | ------------ |
163| encoding | string | Yes   | Encoding string to set.|
164
165## setResponseMimeType<sup>9+</sup>
166
167setResponseMimeType(mimeType: string): void
168
169Sets the MIME type of the resource response.
170
171**System capability**: SystemCapability.Web.Webview.Core
172
173**Parameters**
174
175| Name     | Type  | Mandatory  | Description                |
176| -------- | ------ | ---- | -------------------- |
177| mimeType | string | Yes  | MIME type to set.|
178
179## setReasonMessage<sup>9+</sup>
180
181setReasonMessage(reason: string): void
182
183Sets the status code description of the resource response.
184
185**System capability**: SystemCapability.Web.Webview.Core
186
187**Parameters**
188
189| Name   | Type  | Mandatory  | Description           |
190| ------ | ------ | ---- | --------------- |
191| reason | string | Yes  | Status code description to set.|
192
193## setResponseHeader<sup>9+</sup>
194
195setResponseHeader(header: Array\<Header\>): void
196
197Sets the resource response header.
198
199**System capability**: SystemCapability.Web.Webview.Core
200
201**Parameters**
202
203| Name   | Type                      | Mandatory  | Description      |
204| ------ | -------------------------- | ---- | ---------- |
205| header | Array\<[Header](./arkts-basic-components-web-i.md#header)\> | Yes  | Resource response header to set.|
206
207## setResponseCode<sup>9+</sup>
208
209setResponseCode(code: number): void
210
211Sets the status code of the resource response.
212
213**System capability**: SystemCapability.Web.Webview.Core
214
215**Parameters**
216
217| Name | Type  | Mandatory  | Description         |
218| ---- | ------ | ---- | ------------- |
219| code | number | Yes  | Status code to set. If the resource ends with an error, set the error code by referring to [@ohos.web.netErrorList](arkts-apis-netErrorList.md). Do not set the error code to **ERR_IO_PENDING**, which may block the synchronous **XMLHttpRequest**.|
220
221## setResponseIsReady<sup>9+</sup>
222
223setResponseIsReady(IsReady: boolean): void
224
225Sets whether the resource response data is ready.
226
227**System capability**: SystemCapability.Web.Webview.Core
228
229**Parameters**
230
231| Name  | Type   | Mandatory | Description         |
232| ------- | ------- | ---- | ------------- |
233| IsReady | boolean | Yes  | Whether the resource response data is ready.<br>The value **true** indicates that the resource response data is ready, and **false** indicates the opposite. Default value: **true**.|
234