diff --git a/en/application-dev/reference/apis/js-apis-system-fetch.md b/en/application-dev/reference/apis/js-apis-system-fetch.md index 529dc836e0132e77cae90c08f855d8ecb2c5fe8c..9493227bde6cd57366fc254bcbbf93216271b958 100644 --- a/en/application-dev/reference/apis/js-apis-system-fetch.md +++ b/en/application-dev/reference/apis/js-apis-system-fetch.md @@ -21,8 +21,6 @@ fetch(Object): void Obtains data through a network. -**Required permission**: ohos.permission.INTERNET - **System capability**: SystemCapability.Communication.NetStack **Parameters** @@ -33,7 +31,7 @@ Obtains data through a network. | header | Object | No| Request header.| | method | string | No| Request method. The default value is **GET**. The value can be **OPTIONS**, **GET**, **HEAD**, **POST**, **PUT**, **DELETE **or **TRACE**.| | responseType | string | No| Response type. The return type can be text or JSON. By default, the return type is determined based on **Content-Type** in the header returned by the server. For details, see return values in the **success** callback.| -| success | Function | No| Called when the data is obtained successfully.| +| success | Function | No| Called when the data is obtained successfully. The return value is [FetchResponse](#fetchresponse). | | fail | Function | No| Called when the data failed to be obtained.| | complete | Function | No| Called when the execution is complete.| @@ -46,12 +44,12 @@ Obtains data through a network. | Object | Not set| The default value of **Content-Type** is **application/x-www-form-urlencoded**. The **data** value is encoded based on the URL rule and appended in the request body.| | Object | application/x-www-form-urlencoded | The value of data is encoded based on the URL rule and is used as the request body.| -Return values in the **success** callback +## FetchResponse | Name| Type| Description| | -------- | -------- | -------- | | code | number | Server status code.| -| data | string \| Object | The type of the returned data is determined by **responseType**. For details, see the mapping between **responseType** and **data** in **success** callback.| +| data | string \| Object | The data type is determined by **responseType**. For details, see the mapping between **responseType** and **data** in **success** callback.| | headers | Object | All headers in the response from the server.| **Table 2** Mapping between responseType and data in success callback @@ -87,8 +85,8 @@ export default { ``` -> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**
-> HTTPS is supported by default. To support HTTP, you need to add **"network"** to the **config.json** file, and set the attribute **"cleartextTraffic"** to **true**. That is: +> **NOTE**
+> HTTPS is supported by default. To support HTTP, you need to add **"network"** to the **config.json** file, and set the attribute **"cleartextTraffic"** to **true**. That is: > > ``` > { diff --git a/en/application-dev/reference/apis/js-apis-system-network.md b/en/application-dev/reference/apis/js-apis-system-network.md index 1bf121889896276a676f177300f341da5fb327fe..5fd92bf9e2e58c360ffcd6d6f27408281a53b22a 100644 --- a/en/application-dev/reference/apis/js-apis-system-network.md +++ b/en/application-dev/reference/apis/js-apis-system-network.md @@ -1,6 +1,6 @@ # Network State -> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** +> **NOTE**
> - The APIs of this module are no longer maintained since API version 7. It is recommended that you use [`@ohos.telephony.observer`](js-apis-observer.md) instead. > > - The initial APIs of this module are supported since API version 3. Newly added APIs will be marked with a superscript to indicate their earliest API version. @@ -33,22 +33,15 @@ Obtains the network type. | Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| success | Function | No | Called when the execution is successful. | -| fail | Function | No | Called when the operation fails. | -| complete | Function | No | Called when the execution is complete | - -The following value will be returned when the multimedia volume is obtained. - -| Parameter | Type | Description | -| -------- | -------- | -------- | -| metered | boolean | Whether the billing is based on the data volume. | -| type | string | Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**. | +| success | Function | No | Called when the execution is successful. The return value is [FetchResponse](#fetchresponse). | +| fail | Function | No | Called when the operation fails. | +| complete | Function | No | Called when the execution is complete. | One of the following error codes will be returned if the operation fails. -| Error Code | Description | +| Error Code | Description | | -------- | -------- | -| 602 | The current permission is not declared. | +| 602 | The current permission is not declared. | **Example** @@ -80,22 +73,15 @@ Listens to the network connection state. If this method is called multiple times | Name | Type | Mandatory | Description | | -------- | -------- | -------- | -------- | -| success | Function | No | Called when the network connection state changes | -| fail | Function | No | Called when the multimedia volume fails to be obtained. | - -The following value will be returned when the multimedia volume is obtained. - -| Parameter | Type | Description | -| -------- | -------- | -------- | -| metered | boolean | Whether the billing is based on the data volume. | -| type | string | Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**. | +| success | Function | No | Called when the network connection state changes. The return value is [FetchResponse](#fetchresponse). | +| fail | Function | No | Called when the multimedia volume fails to be obtained. | One of the following error codes will be returned if the listening fails. -| Error Code | Description | +| Error Code | Description | | -------- | -------- | -| 602 | The current permission is not declared. | -| 200 | The subscription fails. | +| 602 | The current permission is not declared. | +| 200 | The subscription fails. | **Example** @@ -131,4 +117,12 @@ export default { network.unsubscribe(); }, } -``` \ No newline at end of file +``` + + +## NetworkResponse + +| Name | Type | Description | +| -------- | -------- | -------- | +| metered | boolean | Whether the billing is based on the data volume. | +| type | string | Network type. The value can be **2G**, **3G**, **4G**, **5G**, **WiFi**, or **none**. | \ No newline at end of file diff --git a/en/application-dev/reference/apis/js-apis-webSocket.md b/en/application-dev/reference/apis/js-apis-webSocket.md index 2b2fa3af70da2fd1725ef0221b8fd7cf5654f531..ae1f200331f1236cf299108ef0e871c4c6dcb6c0 100644 --- a/en/application-dev/reference/apis/js-apis-webSocket.md +++ b/en/application-dev/reference/apis/js-apis-webSocket.md @@ -4,7 +4,7 @@ The **webSocket** module implements WebSocket connection management and operatio > **NOTE**
> The initial APIs of this module are supported since API version 6. Newly added APIs will be marked with a superscript to indicate their earliest API version. -> + You can use WebSocket to establish a bidirectional connection between a server and a client. Before doing this, you need to use the [createWebSocket](#websocketcreatewebsocket) API to create a [WebSocket](#websocket) object and then use the [connect](#connect) API to connect to the server. If the connection is successful, the client will receive a callback of the [open](#onopen) event. Then, the client can communicate with the server using the [send](#send) API. When the server sends a message to the client, the client will receive a callback of the [message](#onmessage) event. If the client no longer needs this connection, it can call the [close](#close) API to disconnect from the server. Then, the client will receive a callback of the [close](#onclose) event.