diff --git a/en/application-dev/connectivity/http-request.md b/en/application-dev/connectivity/http-request.md
index a266e285245c932534873440fc777fd86ccd480d..541f42617439544e81a53d8b3bb8949eb5ec9241 100644
--- a/en/application-dev/connectivity/http-request.md
+++ b/en/application-dev/connectivity/http-request.md
@@ -18,17 +18,10 @@ The following table provides only a simple description of the related APIs. For
| ----------------------------------------- | ----------------------------------- |
| createHttp() | Creates an HTTP request. |
| request() | Initiates an HTTP request to a given URL. |
-| request2()10+ | Initiates an HTTP network request based on the URL and returns a streaming response.|
| destroy() | Destroys an HTTP request. |
| on(type: 'headersReceive') | Registers an observer for HTTP Response Header events. |
| off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events.|
| once\('headersReceive'\)8+ | Registers a one-time observer for HTTP Response Header events.|
-| on\('dataReceive'\)10+ | Registers an observer for events indicating receiving of HTTP streaming responses. |
-| off\('dataReceive'\)10+ | Unregisters the observer for events indicating receiving of HTTP streaming responses. |
-| on\('dataEnd'\)10+ | Registers an observer for events indicating completion of receiving HTTP streaming responses. |
-| off\('dataEnd'\)10+ | Unregisters the observer for events indicating completion of receiving HTTP streaming responses.|
-| on\('dataProgress'\)10+ | Registers an observer for events indicating progress of receiving HTTP streaming responses. |
-| off\('dataProgress'\)10+ | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.|
## How to Develop
@@ -70,7 +63,6 @@ httpRequest.request(
connectTimeout: 60000 // Optional. The default value is 60000, in ms.
readTimeout: 60000, // Optional. The default value is 60000, in ms.
usingProtocol: http.HttpProtocol.HTTP1_1, // Optional. The default protocol type is automatically specified by the system.
- usingProxy: false, // Optional. By default, network proxy is not used. This field is supported since API 10.
}, (err, data) => {
if (!err) {
// data.result carries the HTTP response. Parse the response based on service requirements.
diff --git a/en/application-dev/reference/apis/js-apis-http.md b/en/application-dev/reference/apis/js-apis-http.md
index 9740df66288c3faefb0838b9c7fc5fa999adc3f4..0e443e4668decb55ed3036022ef3567d69d495bd 100644
--- a/en/application-dev/reference/apis/js-apis-http.md
+++ b/en/application-dev/reference/apis/js-apis-http.md
@@ -2,8 +2,10 @@
The **http** module provides the HTTP data request capability. An application can initiate a data request over HTTP. Common HTTP methods include **GET**, **POST**, **OPTIONS**, **HEAD**, **PUT**, **DELETE**, **TRACE**, and **CONNECT**.
-> **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.
+>**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.
+>
## Modules to Import
@@ -11,9 +13,10 @@ The **http** module provides the HTTP data request capability. An application ca
import http from '@ohos.net.http';
```
-## Example
+## Examples
```js
+// Import the http namespace.
import http from '@ohos.net.http';
// Each httpRequest corresponds to an HTTP request task and cannot be reused.
@@ -24,7 +27,7 @@ httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
});
httpRequest.request(
- // Customize EXAMPLE_URL on your own. It is up to you whether to add parameters to the URL.
+ // Customize EXAMPLE_URL in extraData on your own. It is up to you whether to add parameters to the URL.
"EXAMPLE_URL",
{
method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET.
@@ -45,13 +48,15 @@ httpRequest.request(
}, (err, data) => {
if (!err) {
// data.result carries the HTTP response. Parse the response based on service requirements.
- console.info('Result:' + data.result);
- console.info('code:' + data.responseCode);
+ console.info('Result:' + JSON.stringify(data.result));
+ console.info('code:' + JSON.stringify(data.responseCode));
// data.header carries the HTTP response header. Parse the content based on service requirements.
console.info('header:' + JSON.stringify(data.header));
- console.info('cookies:' + data.cookies); // 8+
+ console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
} else {
console.info('error:' + JSON.stringify(err));
+ // Unsubscribe from HTTP Response Header events.
+ httpRequest.off('headersReceive');
// Call the destroy() method to release resources after HttpRequest is complete.
httpRequest.destroy();
}
@@ -61,16 +66,16 @@ httpRequest.request(
## http.createHttp
-createHttp\(\): HttpRequest
+createHttp(): HttpRequest
-Creates an HTTP request. You can use this API to initiate or destroy an HTTP request, or enable or disable listening for HTTP Response Header events. An HttpRequest object corresponds to an HTTP request. To initiate multiple HTTP requests, you must create an **HttpRequest** object for each HTTP request.
+Creates an HTTP request. You can use this API to initiate or destroy an HTTP request, or enable or disable listening for HTTP Response Header events. An **HttpRequest** object corresponds to an HTTP request. To initiate multiple HTTP requests, you must create an **HttpRequest** object for each HTTP request.
**System capability**: SystemCapability.Communication.NetStack
**Return value**
| Type | Description |
-| ---------- | ----------------------------------------------------------- |
+| :---------- | :----------------------------------------------------------- |
| HttpRequest | An **HttpRequest** object, which contains the **request**, **destroy**, **on**, or **off** method.|
**Example**
@@ -82,14 +87,17 @@ let httpRequest = http.createHttp();
## HttpRequest
-Defines an HTTP request task. Before invoking APIs provided by **HttpRequest**, you must call [createHttp\(\)](#httpcreatehttp) to create an **HttpRequestTask** object.
+Defines an HTTP request task. Before invoking APIs provided by **HttpRequest**, you must call [createHttp()](#httpcreatehttp) to create an **HttpRequestTask** object.
### request
-request\(url: string, callback: AsyncCallback\\):void
+request(url: string, callback: AsyncCallback\):void
Initiates an HTTP request to a given URL. This API uses an asynchronous callback to return the result.
+>**NOTE**
+>This API supports only transfer of data not greater than 5 MB.
+
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
@@ -101,6 +109,22 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback
| url | string | Yes | URL for initiating an HTTP request.|
| callback | AsyncCallback\<[HttpResponse](#httpresponse)\> | Yes | Callback used to return the result. |
+**Error codes**
+
+| Code | Error Message |
+|---------|-------------------------------------------------------|
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+| 2300003 | URL using bad/illegal format or missing URL. |
+| 2300007 | Couldn't connect to server. |
+| 2300028 | Timeout was reached. |
+| 2300052 | Server returned nothing (no headers, no data). |
+| 2300999 | Unknown Other Error. |
+
+>**NOTE**
+> For details about the error codes, see [HTTP Error Codes](../errorcodes/errorcode-net-http.md).
+> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html).
+
**Example**
```js
@@ -118,10 +142,13 @@ httpRequest.request("EXAMPLE_URL", (err, data) => {
### request
-request\(url: string, options: HttpRequestOptions, callback: AsyncCallback\):void
+request(url: string, options: HttpRequestOptions, callback: AsyncCallback\):void
Initiates an HTTP request containing specified options to a given URL. This API uses an asynchronous callback to return the result.
+>**NOTE**
+>This API supports only transfer of data not greater than 5 MB.
+
**Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack
@@ -134,6 +161,46 @@ Initiates an HTTP request containing specified options to a given URL. This API
| options | HttpRequestOptions | Yes | Request options. For details, see [HttpRequestOptions](#httprequestoptions).|
| callback | AsyncCallback\<[HttpResponse](#httpresponse)\> | Yes | Callback used to return the result. |
+**Error codes**
+
+| Code | Error Message |
+|---------|-------------------------------------------------------|
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+| 2300001 | Unsupported protocol. |
+| 2300003 | URL using bad/illegal format or missing URL. |
+| 2300005 | Couldn't resolve proxy name. |
+| 2300006 | Couldn't resolve host name. |
+| 2300007 | Couldn't connect to server. |
+| 2300008 | Weird server reply. |
+| 2300009 | Access denied to remote resource. |
+| 2300016 | Error in the HTTP2 framing layer. |
+| 2300018 | Transferred a partial file. |
+| 2300023 | Failed writing received data to disk/application. |
+| 2300025 | Upload failed. |
+| 2300026 | Failed to open/read local data from file/application. |
+| 2300027 | Out of memory. |
+| 2300028 | Timeout was reached. |
+| 2300047 | Number of redirects hit maximum amount. |
+| 2300052 | Server returned nothing (no headers, no data). |
+| 2300055 | Failed sending data to the peer. |
+| 2300056 | Failure when receiving data from the peer. |
+| 2300058 | Problem with the local SSL certificate. |
+| 2300059 | Couldn't use specified SSL cipher. |
+| 2300060 | SSL peer certificate or SSH remote key was not OK. |
+| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.|
+| 2300063 | Maximum file size exceeded. |
+| 2300070 | Disk full or allocation exceeded. |
+| 2300073 | Remote file already exists. |
+| 2300077 | Problem with the SSL CA cert (path? access rights?). |
+| 2300078 | Remote file not found. |
+| 2300094 | An authentication function returned an error. |
+| 2300999 | Unknown Other Error. |
+
+>**NOTE**
+> For details about the error codes, see [HTTP Error Codes](../errorcodes/errorcode-net-http.md).
+> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html).
+
**Example**
```js
@@ -161,9 +228,12 @@ httpRequest.request("EXAMPLE_URL",
### request
-request\(url: string, options? : HttpRequestOptions\): Promise
+request(url: string, options? : HttpRequestOptions): Promise\
+
+Initiates an HTTP request containing specified options to a given URL. This API uses a promise to return the result.
-Initiates an HTTP request to a given URL. This API uses a promise to return the result.
+>**NOTE**
+>This API supports only transfer of data not greater than 5 MB.
**Required permissions**: ohos.permission.INTERNET
@@ -179,9 +249,48 @@ Initiates an HTTP request to a given URL. This API uses a promise to return the
**Return value**
| Type | Description |
-| ------------------------------------- | -------------------------------- |
+| :------------------------------------- | :-------------------------------- |
| Promise<[HttpResponse](#httpresponse)> | Promise used to return the result.|
+**Error codes**
+
+| Code | Error Message |
+|---------|-------------------------------------------------------|
+| 401 | Parameter error. |
+| 201 | Permission denied. |
+| 2300001 | Unsupported protocol. |
+| 2300003 | URL using bad/illegal format or missing URL. |
+| 2300005 | Couldn't resolve proxy name. |
+| 2300006 | Couldn't resolve host name. |
+| 2300007 | Couldn't connect to server. |
+| 2300008 | Weird server reply. |
+| 2300009 | Access denied to remote resource. |
+| 2300016 | Error in the HTTP2 framing layer. |
+| 2300018 | Transferred a partial file. |
+| 2300023 | Failed writing received data to disk/application. |
+| 2300025 | Upload failed. |
+| 2300026 | Failed to open/read local data from file/application. |
+| 2300027 | Out of memory. |
+| 2300028 | Timeout was reached. |
+| 2300047 | Number of redirects hit maximum amount. |
+| 2300052 | Server returned nothing (no headers, no data). |
+| 2300055 | Failed sending data to the peer. |
+| 2300056 | Failure when receiving data from the peer. |
+| 2300058 | Problem with the local SSL certificate. |
+| 2300059 | Couldn't use specified SSL cipher. |
+| 2300060 | SSL peer certificate or SSH remote key was not OK. |
+| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.|
+| 2300063 | Maximum file size exceeded. |
+| 2300070 | Disk full or allocation exceeded. |
+| 2300073 | Remote file already exists. |
+| 2300077 | Problem with the SSL CA cert (path? access rights?). |
+| 2300078 | Remote file not found. |
+| 2300094 | An authentication function returned an error. |
+| 2300999 | Unknown Other Error. |
+
+>**NOTE**
+> For details about the error codes, see [HTTP Error Codes](../errorcodes/errorcode-net-http.md).
+> The HTTP error code mapping is in the format of 2300000 + Curl error code. For more common error codes, see [Curl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html).
**Example**
@@ -208,7 +317,7 @@ promise.then((data) => {
### destroy
-destroy\(\): void
+destroy(): void
Destroys an HTTP request.
@@ -220,14 +329,14 @@ Destroys an HTTP request.
httpRequest.destroy();
```
-### on\('headerReceive'\)
+### on('headerReceive')
-on\(type: 'headerReceive', callback: AsyncCallback