1# Class (WebResourceResponse) 2<!--Kit: ArkWeb--> 3<!--Subsystem: Web--> 4<!--Owner: @aohui--> 5<!--Designer: @yaomingliu--> 6<!--Tester: @ghiker--> 7<!--Adviser: @HelloCrease--> 8 9Web组件资源响应对象。示例代码参考[onHttpErrorReceive事件](./arkts-basic-components-web-events.md#onhttperrorreceive)。 10 11> **说明:** 12> 13> - 该组件首批接口从API version 8开始支持。后续版本如有新增内容,则采用上角标单独标记该内容的起始版本。 14> 15> - 本Class首批接口从API version 8开始支持。 16> 17> - 示例效果请以真机运行为准,当前DevEco Studio预览器不支持。 18 19## constructor 20 21constructor() 22 23WebResourceResponse的构造函数。 24 25**系统能力:** SystemCapability.Web.Webview.Core 26 27## getReasonMessage 28 29getReasonMessage(): string 30 31获取资源响应的状态码描述。 32 33**系统能力:** SystemCapability.Web.Webview.Core 34 35**返回值:** 36 37| 类型 | 说明 | 38| ------ | ------------- | 39| string | 返回资源响应的状态码描述。 | 40 41## getResponseCode 42 43getResponseCode(): number 44 45获取资源响应的状态码。 46 47**系统能力:** SystemCapability.Web.Webview.Core 48 49**返回值:** 50 51| 类型 | 说明 | 52| ------ | ----------- | 53| number | 返回资源响应的状态码。 | 54 55## getResponseData 56 57getResponseData(): string 58 59获取资源响应数据。 60 61**系统能力:** SystemCapability.Web.Webview.Core 62 63**返回值:** 64 65| 类型 | 说明 | 66| ------ | --------- | 67| string | 返回资源响应数据。 | 68 69## getResponseEncoding 70 71getResponseEncoding(): string 72 73获取资源响应的编码。 74 75**系统能力:** SystemCapability.Web.Webview.Core 76 77**返回值:** 78 79| 类型 | 说明 | 80| ------ | ---------- | 81| string | 返回资源响应的编码。 | 82 83## getResponseHeader 84 85getResponseHeader() : Array\<Header\> 86 87获取资源响应头。 88 89**系统能力:** SystemCapability.Web.Webview.Core 90 91**返回值:** 92 93| 类型 | 说明 | 94| -------------------------- | -------- | 95| Array\<[Header](./arkts-basic-components-web-i.md#header)\> | 返回资源响应头。 | 96 97## getResponseMimeType 98 99getResponseMimeType(): string 100 101获取资源响应的媒体(MIME)类型。 102 103**系统能力:** SystemCapability.Web.Webview.Core 104 105**返回值:** 106 107| 类型 | 说明 | 108| ------ | ------------------ | 109| string | 返回资源响应的媒体(MIME)类型。 | 110 111## getResponseDataEx<sup>13+</sup> 112 113getResponseDataEx(): string | number | ArrayBuffer | Resource | undefined 114 115获取资源响应数据,支持多种数据类型。 116 117**系统能力:** SystemCapability.Web.Webview.Core 118 119**返回值:** 120 121|类型|说明| 122|---|---| 123|string \| number \| ArrayBuffer \| [Resource](../apis-arkui/arkui-ts/ts-types.md#resource) \| undefined | string返回HTML格式的字符串。 number返回文件句柄。 ArrayBuffer返回二进制数据。 Resource返回`$rawfile`资源。 如果没有可用数据,返回`undefined`。 | 124 125## getResponseIsReady<sup>13+</sup> 126 127getResponseIsReady(): boolean 128 129获取响应数据是否已准备就绪。 130 131**系统能力:** SystemCapability.Web.Webview.Core 132 133**返回值:** 134 135|类型|说明| 136|---|---| 137|boolean|`true`表示响应数据已准备好,`false`表示未准备好。| 138 139## setResponseData<sup>9+</sup> 140 141setResponseData(data: string \| number \| Resource \| ArrayBuffer): void 142 143设置资源响应数据。 144 145**系统能力:** SystemCapability.Web.Webview.Core 146 147**参数:** 148 149| 参数名 | 类型 | 必填 | 说明 | 150| ---- | ---------------------------------------- | ---- | ---------------------------------------- | 151| data | string \| number \| [Resource](../apis-arkui/arkui-ts/ts-types.md#resource)<sup>10+</sup> \| ArrayBuffer<sup>11+</sup> | 是 | 要设置的资源响应数据。string表示HTML格式的字符串。number表示文件句柄,此句柄由系统的Web组件负责关闭。Resource表示应用rawfile目录下文件资源。ArrayBuffer表示资源的原始二进制数据。 | 152 153## setResponseEncoding<sup>9+</sup> 154 155setResponseEncoding(encoding: string): void 156 157设置资源响应的编码。 158 159**系统能力:** SystemCapability.Web.Webview.Core 160 161**参数:** 162 163| 参数名 | 类型 | 必填 | 说明 | 164| -------- | ------ | ---- | ------------ | 165| encoding | string | 是 | 要设置的资源响应的编码。 | 166 167## setResponseMimeType<sup>9+</sup> 168 169setResponseMimeType(mimeType: string): void 170 171设置资源响应的媒体(MIME)类型。 172 173**系统能力:** SystemCapability.Web.Webview.Core 174 175**参数:** 176 177| 参数名 | 类型 | 必填 | 说明 | 178| -------- | ------ | ---- | -------------------- | 179| mimeType | string | 是 | 要设置的资源响应的媒体(MIME)类型。 | 180 181## setReasonMessage<sup>9+</sup> 182 183setReasonMessage(reason: string): void 184 185设置资源响应的状态码描述。 186 187**系统能力:** SystemCapability.Web.Webview.Core 188 189**参数:** 190 191| 参数名 | 类型 | 必填 | 说明 | 192| ------ | ------ | ---- | --------------- | 193| reason | string | 是 | 要设置的资源响应的状态码描述。 | 194 195## setResponseHeader<sup>9+</sup> 196 197setResponseHeader(header: Array\<Header\>): void 198 199设置资源响应头。 200 201**系统能力:** SystemCapability.Web.Webview.Core 202 203**参数:** 204 205| 参数名 | 类型 | 必填 | 说明 | 206| ------ | -------------------------- | ---- | ---------- | 207| header | Array\<[Header](./arkts-basic-components-web-i.md#header)\> | 是 | 要设置的资源响应头。 | 208 209## setResponseCode<sup>9+</sup> 210 211setResponseCode(code: number): void 212 213设置资源响应的状态码。 214 215**系统能力:** SystemCapability.Web.Webview.Core 216 217**参数:** 218 219| 参数名 | 类型 | 必填 | 说明 | 220| ---- | ------ | ---- | ------------- | 221| code | number | 是 | 要设置的资源响应的状态码。如果该资源以错误结束,请参考[@ohos.web.netErrorList](arkts-apis-netErrorList.md)设置相应错误码,避免设置错误码为 ERR_IO_PENDING,设置为该错误码可能会导致XMLHttpRequest同步请求阻塞。 | 222 223## setResponseIsReady<sup>9+</sup> 224 225setResponseIsReady(IsReady: boolean): void 226 227设置资源响应数据是否已经就绪。 228 229**系统能力:** SystemCapability.Web.Webview.Core 230 231**参数:** 232 233| 参数名 | 类型 | 必填 | 说明 | 234| ------- | ------- | ---- | ------------- | 235| IsReady | boolean | 是 | 资源响应数据是否已经就绪。<br>true表示资源响应数据已经就绪,false表示资源响应数据未就绪。<br>如果数据是异步提供,需要显式设置为false。设置为非法值如null,undefined或者不设置都会被认为数据已经准备好。 |