提交 11529786 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 962bdcf6
...@@ -21,8 +21,6 @@ fetch(Object): void ...@@ -21,8 +21,6 @@ fetch(Object): void
Obtains data through a network. Obtains data through a network.
**Required permission**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
**Parameters** **Parameters**
...@@ -33,7 +31,7 @@ Obtains data through a network. ...@@ -33,7 +31,7 @@ Obtains data through a network.
| header | Object | No| Request header.| | 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**.| | 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.| | 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.| | fail | Function | No| Called when the data failed to be obtained.|
| complete | Function | No| Called when the execution is complete.| | complete | Function | No| Called when the execution is complete.|
...@@ -46,12 +44,12 @@ Obtains data through a network. ...@@ -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 | 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.| | 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| | Name| Type| Description|
| -------- | -------- | -------- | | -------- | -------- | -------- |
| code | number | Server status code.| | 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.| | headers | Object | All headers in the response from the server.|
**Table 2** Mapping between responseType and data in success callback **Table 2** Mapping between responseType and data in success callback
...@@ -87,7 +85,7 @@ export default { ...@@ -87,7 +85,7 @@ export default {
``` ```
> ![icon-note.gif](public_sys-resources/icon-note.gif) **NOTE**<br/> > **NOTE**<br/>
> 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: > 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:
> >
> ``` > ```
......
# Network State # Network State
> ![icon-note.gif](public_sys-resources/icon-note.gif) **Note:** > **NOTE**<br>
> - 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 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. > - 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. ...@@ -33,22 +33,15 @@ Obtains the network type.
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;successful. | | success | Function | No | Called when the execution is successful. The return value is [FetchResponse](#fetchresponse). |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;operation&nbsp;fails. | | fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called&nbsp;when&nbsp;the&nbsp;execution&nbsp;is&nbsp;complete | | 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&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the operation fails. One of the following error codes will be returned if the operation fails.
| Error&nbsp;Code | Description | | Error Code | Description |
| -------- | -------- | | -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. | | 602 | The current permission is not declared. |
**Example** **Example**
...@@ -80,22 +73,15 @@ Listens to the network connection state. If this method is called multiple times ...@@ -80,22 +73,15 @@ Listens to the network connection state. If this method is called multiple times
| Name | Type | Mandatory | Description | | Name | Type | Mandatory | Description |
| -------- | -------- | -------- | -------- | | -------- | -------- | -------- | -------- |
| success | Function | No | Called&nbsp;when&nbsp;the&nbsp;network&nbsp;connection&nbsp;state&nbsp;changes | | success | Function | No | Called when the network connection state changes. The return value is [FetchResponse](#fetchresponse). |
| fail | Function | No | Called&nbsp;when&nbsp;the&nbsp;multimedia&nbsp;volume&nbsp;fails&nbsp;to&nbsp;be&nbsp;obtained. | | 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&nbsp;the&nbsp;billing&nbsp;is&nbsp;based&nbsp;on&nbsp;the&nbsp;data&nbsp;volume. |
| type | string | Network&nbsp;type.&nbsp;The&nbsp;value&nbsp;can&nbsp;be&nbsp;**2G**,&nbsp;**3G**,&nbsp;**4G**,&nbsp;**5G**,&nbsp;**WiFi**,&nbsp;or&nbsp;**none**. |
One of the following error codes will be returned if the listening fails. One of the following error codes will be returned if the listening fails.
| Error&nbsp;Code | Description | | Error Code | Description |
| -------- | -------- | | -------- | -------- |
| 602 | The&nbsp;current&nbsp;permission&nbsp;is&nbsp;not&nbsp;declared. | | 602 | The current permission is not declared. |
| 200 | The&nbsp;subscription&nbsp;fails. | | 200 | The subscription fails. |
**Example** **Example**
...@@ -132,3 +118,11 @@ export default { ...@@ -132,3 +118,11 @@ export default {
}, },
} }
``` ```
## 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
...@@ -4,7 +4,7 @@ The **webSocket** module implements WebSocket connection management and operatio ...@@ -4,7 +4,7 @@ The **webSocket** module implements WebSocket connection management and operatio
> **NOTE**<br> > **NOTE**<br>
> 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. > 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. 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.
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册