From eb942b8afc38ce27122be4c2e7d0f34010ddef44 Mon Sep 17 00:00:00 2001 From: shawn_he Date: Tue, 28 Mar 2023 14:14:02 +0800 Subject: [PATCH] update doc Signed-off-by: shawn_he --- .../connectivity/http-request.md | 8 - .../reference/apis/js-apis-http.md | 244 ++++++++++++------ .../reference/apis/js-apis-net-connection.md | 173 ------------- .../reference/apis/js-apis-socket.md | 2 +- 4 files changed, 169 insertions(+), 258 deletions(-) diff --git a/en/application-dev/connectivity/http-request.md b/en/application-dev/connectivity/http-request.md index a266e28524..541f426174 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 9740df6628..0e443e4668 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\): void +on(type: 'headerReceive', callback: AsyncCallback\): void Registers an observer for HTTP Response Header events. >**NOTE** ->This API has been deprecated. You are advised to use [on\('headersReceive'\)8+](#onheadersreceive8) instead. +>This API has been deprecated. You are advised to use [on('headersReceive')8+](#onheadersreceive8) instead. **System capability**: SystemCapability.Communication.NetStack @@ -241,24 +350,20 @@ Registers an observer for HTTP Response Header events. **Example** ```js -httpRequest.on('headerReceive', (err, data) => { - if (!err) { - console.info('header: ' + JSON.stringify(data)); - } else { - console.info('error:' + JSON.stringify(err)); - } +httpRequest.on('headerReceive', (data) => { + console.info('error:' + JSON.stringify(data)); }); ``` -### off\('headerReceive'\) +### off('headerReceive') -off\(type: 'headerReceive', callback?: AsyncCallback\): void +off(type: 'headerReceive', callback?: AsyncCallback\): void Unregisters the observer for HTTP Response Header events. >**NOTE** > ->1. This API has been deprecated. You are advised to use [off\('headersReceive'\)8+](#offheadersreceive8) instead. +>1. This API has been deprecated. You are advised to use [off('headersReceive')8+](#offheadersreceive8) instead. > >2. You can pass the callback of the **on** function if you want to cancel listening for a certain type of event. If you do not pass the callback, you will cancel listening for all events. @@ -277,9 +382,9 @@ Unregisters the observer for HTTP Response Header events. httpRequest.off('headerReceive'); ``` -### on\('headersReceive'\)8+ +### on('headersReceive')8+ -on\(type: 'headersReceive', callback: Callback\): void +on(type: 'headersReceive', callback: Callback\): void Registers an observer for HTTP Response Header events. @@ -300,9 +405,9 @@ httpRequest.on('headersReceive', (header) => { }); ``` -### off\('headersReceive'\)8+ +### off('headersReceive')8+ -off\(type: 'headersReceive', callback?: Callback\): void +off(type: 'headersReceive', callback?: Callback\): void Unregisters the observer for HTTP Response Header events. @@ -324,9 +429,9 @@ Unregisters the observer for HTTP Response Header events. httpRequest.off('headersReceive'); ``` -### once\('headersReceive'\)8+ +### once('headersReceive')8+ -once\(type: 'headersReceive', callback: Callback\): void +once(type: 'headersReceive', callback: Callback\): void Registers a one-time observer for HTTP Response Header events. Once triggered, the observer will be removed. This API uses an asynchronous callback to return the result. @@ -357,13 +462,13 @@ Specifies the type and value range of the optional parameters in the HTTP reques | -------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ | | method | [RequestMethod](#requestmethod) | No | Request method. | | extraData | string \| Object \| ArrayBuffer6+ | No | Additional data of the request.
- If the HTTP request uses a POST or PUT method, this parameter serves as the content of the HTTP request.
- If the HTTP request uses a GET, OPTIONS, DELETE, TRACE, or CONNECT method, this parameter is a supplement to the HTTP request parameters and will be added to the URL when the request is sent.6+
- To pass in a string object, you first need to encode the object on your own.6+ | -| expectDataType9+ | [HttpDataType](#httpdatatype9) | No | Type of the return data. If this parameter is set, the system returns the specified type of data preferentially.| +| expectDataType9+ | [HttpDataType](#httpdatatype9) | No | Type of the return data. If this parameter is set, the system returns the specified type of data preferentially.| | usingCache9+ | boolean | No | Whether to use the cache. The default value is **true**. | | priority9+ | number | No | Priority. The value range is \[1,1000]. The default value is **1**. | -| header | Object | No | HTTP request header. The default value is **{'Content-Type': 'application/json'}**. | -| readTimeout | number | No | Read timeout duration. The default value is **60000**, in ms. | -| connectTimeout | number | No | Connection timeout interval. The default value is **60000**, in ms. | -| usingProtocol9+ | [HttpProtocol](#httpprotocol9) | No | Protocol. The default value is automatically specified by the system. | +| header | Object | No | HTTP request header. The default value is **{'Content-Type': 'application/json'}**. | +| readTimeout | number | No | Read timeout duration. The default value is **60000**, in ms. | +| connectTimeout | number | No | Connection timeout interval. The default value is **60000**, in ms. | +| usingProtocol9+ | [HttpProtocol](#httpprotocol9) | No | Protocol. The default value is automatically specified by the system. | ## RequestMethod @@ -372,7 +477,7 @@ Defines an HTTP request method. **System capability**: SystemCapability.Communication.NetStack | Name | Value | Description | -| ------ | ------- | ------------------ | +| :------ | ------- | :------------------ | | OPTIONS | "OPTIONS" | OPTIONS method.| | GET | "GET" | GET method. | | HEAD | "HEAD" | HEAD method. | @@ -436,9 +541,9 @@ Defines the response to an HTTP request. | -------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | | result | string \| Object \| ArrayBuffer6+ | Yes | Response content returned based on **Content-type** in the response header:
- application/json: a string in JSON format. If you want to use specific content in the response, you need to implement parsing of that content.
- application/octet-stream: ArrayBuffer
- Others: string| | resultType9+ | [HttpDataType](#httpdatatype9) | Yes | Type of the return value. | -| responseCode | [ResponseCode](#responsecode) \| number | Yes | Result code for an HTTP request. If the callback function is successfully executed, a result code defined in [ResponseCode](#responsecode) will be returned. Otherwise, an error code will be returned in the **err** field in **AsyncCallback**. For details, see [Error Codes](#error-codes).| +| responseCode | [ResponseCode](#responsecode) \| number | Yes | Result code for an HTTP request. If the callback function is successfully executed, a result code defined in [ResponseCode](#responsecode) will be returned. Otherwise, an error code will be returned in the **err** field in **AsyncCallback**.| | header | Object | Yes | Response header. The return value is a string in JSON format. If you want to use specific content in the response, you need to implement parsing of that content. Common fields and parsing methods are as follows:
- Content-Type: header['Content-Type'];
- Status-Line: header['Status-Line'];
- Date: header.Date/header['Date'];
- Server: header.Server/header['Server'];| -| cookies8+ | Array\ | Yes | Cookies returned by the server. | +| cookies8+ | string | Yes | Cookies returned by the server. | ## http.createHttpResponseCache9+ @@ -457,7 +562,7 @@ Creates a default object to store responses to HTTP access requests. **Return value** | Type | Description | -| ---------- | ----------------------------------------------------------- | +| :---------- | :----------------------------------------------------------- | | [HttpResponseCache](#httpresponsecache9) | Object that stores the response to the HTTP request.| **Example** @@ -469,11 +574,11 @@ let httpResponseCache = http.createHttpResponseCache(); ## HttpResponseCache9+ -Defines an object that stores the response to an HTTP request. +Defines an object that stores the response to an HTTP request. Before invoking APIs provided by **HttpResponseCache**, you must call [createHttpResponseCache()](#httpcreatehttpresponsecache9) to create an **HttpRequestTask** object. ### flush9+ -flush(callback: AsyncCallback\): void +flush(callback: AsyncCallback\): void Flushes data in the cache to the file system so that the cached data can be accessed in the next HTTP request. This API uses an asynchronous callback to return the result. @@ -483,23 +588,23 @@ Flushes data in the cache to the file system so that the cached data can be acce | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js httpResponseCache.flush(err => { if (err) { - console.log('flush fail'); + console.info('flush fail'); return; } - console.log('flush success'); + console.info('flush success'); }); ``` ### flush9+ -flush(): Promise\ +flush(): Promise\ Flushes data in the cache to the file system so that the cached data can be accessed in the next HTTP request. This API uses a promise to return the result. @@ -509,21 +614,21 @@ Flushes data in the cache to the file system so that the cached data can be acce | Type | Description | | --------------------------------- | ------------------------------------- | -| Promise\> | Promise used to return the result.| +| Promise\ | Promise used to return the result.| **Example** ```js httpResponseCache.flush().then(() => { - console.log('flush success'); + console.info('flush success'); }).catch(err => { - console.log('flush fail'); + console.info('flush fail'); }); ``` ### delete9+ -delete(callback: AsyncCallback\): void +delete(callback: AsyncCallback\): void Disables the cache and deletes the data in it. This API uses an asynchronous callback to return the result. @@ -533,22 +638,22 @@ Disables the cache and deletes the data in it. This API uses an asynchronous cal | Name | Type | Mandatory| Description | | -------- | --------------------------------------- | ---- | ---------- | -| callback | AsyncCallback\ | Yes | Callback used to return the result.| +| callback | AsyncCallback\ | Yes | Callback used to return the result.| **Example** ```js httpResponseCache.delete(err => { if (err) { - console.log('delete fail'); + console.info('delete fail'); return; } - console.log('delete success'); + console.info('delete success'); }); ``` ### delete9+ -delete(): Promise\ +delete(): Promise\ Disables the cache and deletes the data in it. This API uses a promise to return the result. @@ -558,31 +663,18 @@ Disables the cache and deletes the data in it. This API uses a promise to return | Type | Description | | --------------------------------- | ------------------------------------- | -| Promise\ | Promise used to return the result.| +| Promise\ | Promise used to return the result.| **Example** ```js httpResponseCache.delete().then(() => { - console.log('delete success'); + console.info('delete success'); }).catch(err => { - console.log('delete fail'); + console.info('delete fail'); }); ``` -## Error Codes - -| Error Code| Description | -| ------ | ------------------------------------------------------------ | -| -1 | Incorrect parameter. Check whether the number and type of parameters are correct. | -| 3 | Incorrect URL format. Check whether the format and syntax of the URL are correct. | -| 4 | Built-in request function, protocol, or option not found during build. If a function or option is not enabled or explicitly disabled, you need to rebuild a libcurl in order to access its functions. | -| 5 | Unable to resolve the proxy because of a failure to resolve the specified proxy server. You are advised perform the following: 1. Check whether the URL is correct. 2. Check whether the network connection is normal and whether the network can communicate with external networks. 3. Check whether the network access permission is available. | -| 6 | Unable to resolve the host because of a failure to resolve the specified remote host. You are advised perform the following: 1. Check whether the URL is correct. 2. Check whether the network connection is normal and whether the network can communicate with external networks. 3. Check whether the network access permission is available. | -| 7 | Unable to connect to the proxy or host. You are advised perform the following: 1. Check whether the port number is correct. 2. Check whether the HTTP proxy is enabled on the local host. | - -For details about the error codes, see [libcurl Error Codes](https://curl.se/libcurl/c/libcurl-errors.html). - ## HttpDataType9+ Enumerates HTTP data types. @@ -590,7 +682,7 @@ Enumerates HTTP data types. **System capability**: SystemCapability.Communication.NetStack | Name| Value| Description | -| ------------------ | -- | ----------- | +| ------------------ | -- | ----------- | | STRING | 0 | String type.| | OBJECT | 1 | Object type. | | ARRAY_BUFFER | 2 | Binary array type.| @@ -602,6 +694,6 @@ Enumerates HTTP protocol versions. **System capability**: SystemCapability.Communication.NetStack | Name | Description | -| -------- | ----------- | +| :-------- | :----------- | | HTTP1_1 | HTTP1.1 | | HTTP2 | HTTP2 | diff --git a/en/application-dev/reference/apis/js-apis-net-connection.md b/en/application-dev/reference/apis/js-apis-net-connection.md index adb1c8ee47..efa97d016e 100644 --- a/en/application-dev/reference/apis/js-apis-net-connection.md +++ b/en/application-dev/reference/apis/js-apis-net-connection.md @@ -140,167 +140,6 @@ Obtains the default active data network in synchronous mode. You can use [getNet let netHandle = connection.getDefaultNetSync(); ``` -## connection.getGlobalHttpProxy10+ - -getGlobalHttpProxy(callback: AsyncCallback\): void - -Obtains the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**System capability**: SystemCapability.Communication.NetManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| callback | AsyncCallback\<[HttpProxy](#httpproxy)> | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is obtained successfully, **err** is **undefined** and **data** is the global HTTP proxy configuration. Otherwise, **err** is an error object.| - -**Error codes** - -| ID| Error Message | -| ------- | ----------------------------- | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**Example** - -```js -connection.getGlobalHttpProxy((error,data) => { - console.info(JSON.stringify(error)); - console.info(JSON.stringify(data)); -}) -``` - -## connection.getGlobalHttpProxy10+ - -getGlobalHttpProxy(): Promise\; - -Obtains the global HTTP proxy configuration of the network. This API uses a promise to return the result. - -**System API**: This is a system API. - -**System capability**: SystemCapability.Communication.NetManager.Core - -**Return value** - -| Type | Description | -| --------------------------------- | ------------------------------------- | -| Promise\<[HttpProxy](#httpproxy)> | Promise used to return the result.| - -**Error codes** - -| ID| Error Message | -| ------- | ----------------------------- | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**Example** - -```js -connection.getGlobalHttpProxy().then((data) => { - console.info(JSON.stringify(data)); -}).catch(error => { - console.info(JSON.stringify(error)); -}) -``` - -## connection.setGlobalHttpProxy10+ - -setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\): void - -Sets the global HTTP proxy configuration of the network. This API uses an asynchronous callback to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL - -**System capability**: SystemCapability.Communication.NetManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network.| -| callback | AsyncCallback\ | Yes | Callback used to return the result. If the global HTTP proxy configuration of the network is set successfully, **err** is **undefined**. Otherwise, **err** is an error object.| - -**Error codes** - -| ID| Error Message | -| ------- | ----------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | -| 2100001 | Invalid parameter value. | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**Example** - -```js -let exclusionStr="192.168,baidu.com" -let exclusionArray = exclusionStr.split(','); -let httpProxy = { - host: "192.168.xx.xxx", - port: 8080, - exclusionList: exclusionArray -} -connection.setGlobalHttpProxy(httpProxy, (error, data) => { - console.info(JSON.stringify(error)); - console.info(JSON.stringify(data)); -}); -``` - -## connection.setGlobalHttpProxy10+ - -setGlobalHttpProxy(httpProxy: HttpProxy): Promise\; - -Sets the global HTTP proxy configuration of the network. This API uses a promise to return the result. - -**System API**: This is a system API. - -**Required permissions**: ohos.permission.CONNECTIVITY_INTERNAL - -**System capability**: SystemCapability.Communication.NetManager.Core - -**Parameters** - -| Name | Type | Mandatory| Description | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| httpProxy | [HttpProxy](#httpproxy) | Yes | Global HTTP proxy configuration of the network.| - -**Return value** - -| Type | Description | -| ------------------------------------------- | ----------------------------- | -| Promise\ | Promise that returns no value.| - -**Error codes** - -| ID| Error Message | -| ------- | ----------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | -| 2100001 | Invalid parameter value. | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**Example** - -```js -let exclusionStr="192.168,baidu.com" -let exclusionArray = exclusionStr.split(','); -let httpProxy = { - host: "192.168.xx.xxx", - port: 8080, - exclusionList: exclusionArray -} -connection.setGlobalHttpProxy(httpProxy).then((error, data) => { - console.info(JSON.stringify(data)); -}).catch(error=>{ - console.info(JSON.stringify(error)); -}) -``` - ## connection.getAppNet9+ getAppNet(callback: AsyncCallback\): void @@ -1823,18 +1662,6 @@ Enumerates network types. | BEARER_WIFI | 1 | Wi-Fi network.| | BEARER_ETHERNET | 3 | Ethernet network.| -## HttpProxy10+ - -Defines the global HTTP proxy configuration of the network. - -**System capability**: SystemCapability.Communication.NetManager.Core - -| Name | Type | Mandatory| Description | -| ------ | ------ | --- |------------------------- | -| host | string | No | Host name of the proxy server.| -| port | number | No | Host port.| -| exclusionList | Array | No | List of hosts that do not use the proxy server.| - ## NetSpecifier Provides an instance that bears data network capabilities. diff --git a/en/application-dev/reference/apis/js-apis-socket.md b/en/application-dev/reference/apis/js-apis-socket.md index f099ece8f2..f8952db4df 100644 --- a/en/application-dev/reference/apis/js-apis-socket.md +++ b/en/application-dev/reference/apis/js-apis-socket.md @@ -2672,4 +2672,4 @@ Defines the certificate raw data. | Type | Description | | --------------------------------------------------------------------- | --------------------- | -|[cryptoFramework.EncodingBlob](js-apis-cryptoFramework.md#datablob) | Data and encoding format of the certificate.| +|[cert.EncodingBlob](js-apis-cert.md#datablob) | Data and encoding format of the certificate.| -- GitLab