| 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
> 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:
> - 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 when the execution is successful. |
| success | Function | No | Called when the execution is successful. The return value is [FetchResponse](#fetchresponse). |
| fail | Function | No | Called when the operation fails. |
| fail | Function | No | Called when the operation fails. |
| complete | Function | No | Called when the execution is complete |
| complete | Function | No | Called when the execution is complete. |
The following value will be returned when the multimedia volume is obtained.
@@ -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.