“dec61ab6dfca6a977d39fe899ece2389d4c4e2e0”上不存在“paddle/cuda/git@gitcode.net:s920243400/PaddleDetection.git”
提交 eb942b8a 编写于 作者: S shawn_he

update doc

Signed-off-by: Nshawn_he <shawn.he@huawei.com>
上级 81e87538
...@@ -18,17 +18,10 @@ The following table provides only a simple description of the related APIs. For ...@@ -18,17 +18,10 @@ The following table provides only a simple description of the related APIs. For
| ----------------------------------------- | ----------------------------------- | | ----------------------------------------- | ----------------------------------- |
| createHttp() | Creates an HTTP request. | | createHttp() | Creates an HTTP request. |
| request() | Initiates an HTTP request to a given URL. | | request() | Initiates an HTTP request to a given URL. |
| request2()<sup>10+</sup> | Initiates an HTTP network request based on the URL and returns a streaming response.|
| destroy() | Destroys an HTTP request. | | destroy() | Destroys an HTTP request. |
| on(type: 'headersReceive') | Registers an observer for HTTP Response Header events. | | on(type: 'headersReceive') | Registers an observer for HTTP Response Header events. |
| off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events.| | off(type: 'headersReceive') | Unregisters the observer for HTTP Response Header events.|
| once\('headersReceive'\)<sup>8+</sup> | Registers a one-time observer for HTTP Response Header events.| | once\('headersReceive'\)<sup>8+</sup> | Registers a one-time observer for HTTP Response Header events.|
| on\('dataReceive'\)<sup>10+</sup> | Registers an observer for events indicating receiving of HTTP streaming responses. |
| off\('dataReceive'\)<sup>10+</sup> | Unregisters the observer for events indicating receiving of HTTP streaming responses. |
| on\('dataEnd'\)<sup>10+</sup> | Registers an observer for events indicating completion of receiving HTTP streaming responses. |
| off\('dataEnd'\)<sup>10+</sup> | Unregisters the observer for events indicating completion of receiving HTTP streaming responses.|
| on\('dataProgress'\)<sup>10+</sup> | Registers an observer for events indicating progress of receiving HTTP streaming responses. |
| off\('dataProgress'\)<sup>10+</sup> | Unregisters the observer for events indicating progress of receiving HTTP streaming responses.|
## How to Develop ## How to Develop
...@@ -70,7 +63,6 @@ httpRequest.request( ...@@ -70,7 +63,6 @@ httpRequest.request(
connectTimeout: 60000 // Optional. The default value is 60000, in ms. connectTimeout: 60000 // Optional. The default value is 60000, in ms.
readTimeout: 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. 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) => { }, (err, data) => {
if (!err) { if (!err) {
// data.result carries the HTTP response. Parse the response based on service requirements. // data.result carries the HTTP response. Parse the response based on service requirements.
......
...@@ -2,8 +2,10 @@ ...@@ -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**. 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**<br> >**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. >
>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 ## Modules to Import
...@@ -11,9 +13,10 @@ The **http** module provides the HTTP data request capability. An application ca ...@@ -11,9 +13,10 @@ The **http** module provides the HTTP data request capability. An application ca
import http from '@ohos.net.http'; import http from '@ohos.net.http';
``` ```
## Example ## Examples
```js ```js
// Import the http namespace.
import http from '@ohos.net.http'; import http from '@ohos.net.http';
// Each httpRequest corresponds to an HTTP request task and cannot be reused. // Each httpRequest corresponds to an HTTP request task and cannot be reused.
...@@ -24,7 +27,7 @@ httpRequest.on('headersReceive', (header) => { ...@@ -24,7 +27,7 @@ httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header)); console.info('header: ' + JSON.stringify(header));
}); });
httpRequest.request( 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", "EXAMPLE_URL",
{ {
method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET. method: http.RequestMethod.POST, // Optional. The default value is http.RequestMethod.GET.
...@@ -45,13 +48,15 @@ httpRequest.request( ...@@ -45,13 +48,15 @@ httpRequest.request(
}, (err, data) => { }, (err, data) => {
if (!err) { if (!err) {
// data.result carries the HTTP response. Parse the response based on service requirements. // data.result carries the HTTP response. Parse the response based on service requirements.
console.info('Result:' + data.result); console.info('Result:' + JSON.stringify(data.result));
console.info('code:' + data.responseCode); console.info('code:' + JSON.stringify(data.responseCode));
// data.header carries the HTTP response header. Parse the content based on service requirements. // data.header carries the HTTP response header. Parse the content based on service requirements.
console.info('header:' + JSON.stringify(data.header)); console.info('header:' + JSON.stringify(data.header));
console.info('cookies:' + data.cookies); // 8+ console.info('cookies:' + JSON.stringify(data.cookies)); // 8+
} else { } else {
console.info('error:' + JSON.stringify(err)); 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. // Call the destroy() method to release resources after HttpRequest is complete.
httpRequest.destroy(); httpRequest.destroy();
} }
...@@ -61,16 +66,16 @@ httpRequest.request( ...@@ -61,16 +66,16 @@ httpRequest.request(
## http.createHttp ## 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 **System capability**: SystemCapability.Communication.NetStack
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------- | ----------------------------------------------------------- | | :---------- | :----------------------------------------------------------- |
| HttpRequest | An **HttpRequest** object, which contains the **request**, **destroy**, **on**, or **off** method.| | HttpRequest | An **HttpRequest** object, which contains the **request**, **destroy**, **on**, or **off** method.|
**Example** **Example**
...@@ -82,14 +87,17 @@ let httpRequest = http.createHttp(); ...@@ -82,14 +87,17 @@ let httpRequest = http.createHttp();
## HttpRequest ## 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
request\(url: string, callback: AsyncCallback\<HttpResponse\>\):void request(url: string, callback: AsyncCallback\<HttpResponse\>):void
Initiates an HTTP request to a given URL. This API uses an asynchronous callback to return the result. 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 **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -101,6 +109,22 @@ Initiates an HTTP request to a given URL. This API uses an asynchronous callback ...@@ -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.| | url | string | Yes | URL for initiating an HTTP request.|
| callback | AsyncCallback\<[HttpResponse](#httpresponse)\> | Yes | Callback used to return the result. | | 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** **Example**
```js ```js
...@@ -118,10 +142,13 @@ httpRequest.request("EXAMPLE_URL", (err, data) => { ...@@ -118,10 +142,13 @@ httpRequest.request("EXAMPLE_URL", (err, data) => {
### request ### request
request\(url: string, options: HttpRequestOptions, callback: AsyncCallback<HttpResponse\>\):void request(url: string, options: HttpRequestOptions, callback: AsyncCallback\<HttpResponse\>):void
Initiates an HTTP request containing specified options to a given URL. This API uses an asynchronous callback to return the result. 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 **Required permissions**: ohos.permission.INTERNET
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -134,6 +161,46 @@ Initiates an HTTP request containing specified options to a given URL. This API ...@@ -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).| | options | HttpRequestOptions | Yes | Request options. For details, see [HttpRequestOptions](#httprequestoptions).|
| callback | AsyncCallback\<[HttpResponse](#httpresponse)\> | Yes | Callback used to return the result. | | 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** **Example**
```js ```js
...@@ -161,9 +228,12 @@ httpRequest.request("EXAMPLE_URL", ...@@ -161,9 +228,12 @@ httpRequest.request("EXAMPLE_URL",
### request ### request
request\(url: string, options? : HttpRequestOptions\): Promise<HttpResponse\> request(url: string, options? : HttpRequestOptions): Promise\<HttpResponse\>
Initiates an HTTP request to a given URL. This API uses a promise to return the result. Initiates an HTTP request containing specified options 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 **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 ...@@ -179,9 +249,48 @@ Initiates an HTTP request to a given URL. This API uses a promise to return the
**Return value** **Return value**
| Type | Description | | Type | Description |
| ------------------------------------- | -------------------------------- | | :------------------------------------- | :-------------------------------- |
| Promise<[HttpResponse](#httpresponse)> | Promise used to return the result.| | 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** **Example**
...@@ -208,7 +317,7 @@ promise.then((data) => { ...@@ -208,7 +317,7 @@ promise.then((data) => {
### destroy ### destroy
destroy\(\): void destroy(): void
Destroys an HTTP request. Destroys an HTTP request.
...@@ -220,14 +329,14 @@ Destroys an HTTP request. ...@@ -220,14 +329,14 @@ Destroys an HTTP request.
httpRequest.destroy(); httpRequest.destroy();
``` ```
### on\('headerReceive'\) ### on('headerReceive')
on\(type: 'headerReceive', callback: AsyncCallback<Object\>\): void on(type: 'headerReceive', callback: AsyncCallback\<Object\>): void
Registers an observer for HTTP Response Header events. Registers an observer for HTTP Response Header events.
>**NOTE** >**NOTE**
>This API has been deprecated. You are advised to use [on\('headersReceive'\)<sup>8+</sup>](#onheadersreceive8) instead. >This API has been deprecated. You are advised to use [on('headersReceive')<sup>8+</sup>](#onheadersreceive8) instead.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
...@@ -241,24 +350,20 @@ Registers an observer for HTTP Response Header events. ...@@ -241,24 +350,20 @@ Registers an observer for HTTP Response Header events.
**Example** **Example**
```js ```js
httpRequest.on('headerReceive', (err, data) => { httpRequest.on('headerReceive', (data) => {
if (!err) { console.info('error:' + JSON.stringify(data));
console.info('header: ' + JSON.stringify(data));
} else {
console.info('error:' + JSON.stringify(err));
}
}); });
``` ```
### off\('headerReceive'\) ### off('headerReceive')
off\(type: 'headerReceive', callback?: AsyncCallback<Object\>\): void off(type: 'headerReceive', callback?: AsyncCallback\<Object\>): void
Unregisters the observer for HTTP Response Header events. Unregisters the observer for HTTP Response Header events.
>**NOTE** >**NOTE**
> >
>1. This API has been deprecated. You are advised to use [off\('headersReceive'\)<sup>8+</sup>](#offheadersreceive8) instead. >1. This API has been deprecated. You are advised to use [off('headersReceive')<sup>8+</sup>](#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. >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. ...@@ -277,9 +382,9 @@ Unregisters the observer for HTTP Response Header events.
httpRequest.off('headerReceive'); httpRequest.off('headerReceive');
``` ```
### on\('headersReceive'\)<sup>8+</sup> ### on('headersReceive')<sup>8+</sup>
on\(type: 'headersReceive', callback: Callback<Object\>\): void on(type: 'headersReceive', callback: Callback\<Object\>): void
Registers an observer for HTTP Response Header events. Registers an observer for HTTP Response Header events.
...@@ -300,9 +405,9 @@ httpRequest.on('headersReceive', (header) => { ...@@ -300,9 +405,9 @@ httpRequest.on('headersReceive', (header) => {
}); });
``` ```
### off\('headersReceive'\)<sup>8+</sup> ### off('headersReceive')<sup>8+</sup>
off\(type: 'headersReceive', callback?: Callback<Object\>\): void off(type: 'headersReceive', callback?: Callback\<Object\>): void
Unregisters the observer for HTTP Response Header events. Unregisters the observer for HTTP Response Header events.
...@@ -324,9 +429,9 @@ Unregisters the observer for HTTP Response Header events. ...@@ -324,9 +429,9 @@ Unregisters the observer for HTTP Response Header events.
httpRequest.off('headersReceive'); httpRequest.off('headersReceive');
``` ```
### once\('headersReceive'\)<sup>8+</sup> ### once('headersReceive')<sup>8+</sup>
once\(type: 'headersReceive', callback: Callback<Object\>\): void once(type: 'headersReceive', callback: Callback\<Object\>): 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. 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.
...@@ -372,7 +477,7 @@ Defines an HTTP request method. ...@@ -372,7 +477,7 @@ Defines an HTTP request method.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
| Name | Value | Description | | Name | Value | Description |
| ------ | ------- | ------------------ | | :------ | ------- | :------------------ |
| OPTIONS | "OPTIONS" | OPTIONS method.| | OPTIONS | "OPTIONS" | OPTIONS method.|
| GET | "GET" | GET method. | | GET | "GET" | GET method. |
| HEAD | "HEAD" | HEAD method. | | HEAD | "HEAD" | HEAD method. |
...@@ -436,9 +541,9 @@ Defines the response to an HTTP request. ...@@ -436,9 +541,9 @@ Defines the response to an HTTP request.
| -------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ | | -------------------- | -------------------------------------------- | ---- | ------------------------------------------------------------ |
| result | string \| Object \| ArrayBuffer<sup>6+</sup> | Yes | Response content returned based on **Content-type** in the response header:<br>- 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.<br>- application/octet-stream: ArrayBuffer<br>- Others: string| | result | string \| Object \| ArrayBuffer<sup>6+</sup> | Yes | Response content returned based on **Content-type** in the response header:<br>- 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.<br>- application/octet-stream: ArrayBuffer<br>- Others: string|
| resultType<sup>9+</sup> | [HttpDataType](#httpdatatype9) | Yes | Type of the return value. | | resultType<sup>9+</sup> | [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:<br>- Content-Type: header['Content-Type'];<br>- Status-Line: header['Status-Line'];<br>- Date: header.Date/header['Date'];<br>- Server: header.Server/header['Server'];| | 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:<br>- Content-Type: header['Content-Type'];<br>- Status-Line: header['Status-Line'];<br>- Date: header.Date/header['Date'];<br>- Server: header.Server/header['Server'];|
| cookies<sup>8+</sup> | Array\<string\> | Yes | Cookies returned by the server. | | cookies<sup>8+</sup> | string | Yes | Cookies returned by the server. |
## http.createHttpResponseCache<sup>9+</sup> ## http.createHttpResponseCache<sup>9+</sup>
...@@ -457,7 +562,7 @@ Creates a default object to store responses to HTTP access requests. ...@@ -457,7 +562,7 @@ Creates a default object to store responses to HTTP access requests.
**Return value** **Return value**
| Type | Description | | Type | Description |
| ---------- | ----------------------------------------------------------- | | :---------- | :----------------------------------------------------------- |
| [HttpResponseCache](#httpresponsecache9) | Object that stores the response to the HTTP request.| | [HttpResponseCache](#httpresponsecache9) | Object that stores the response to the HTTP request.|
**Example** **Example**
...@@ -469,11 +574,11 @@ let httpResponseCache = http.createHttpResponseCache(); ...@@ -469,11 +574,11 @@ let httpResponseCache = http.createHttpResponseCache();
## HttpResponseCache<sup>9+</sup> ## HttpResponseCache<sup>9+</sup>
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.
### flush<sup>9+</sup> ### flush<sup>9+</sup>
flush(callback: AsyncCallback\<void>): void flush(callback: AsyncCallback\<void\>): 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. 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 ...@@ -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 | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- | | -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
httpResponseCache.flush(err => { httpResponseCache.flush(err => {
if (err) { if (err) {
console.log('flush fail'); console.info('flush fail');
return; return;
} }
console.log('flush success'); console.info('flush success');
}); });
``` ```
### flush<sup>9+</sup> ### flush<sup>9+</sup>
flush(): Promise\<void> flush(): Promise\<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 a promise to return the result. 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 ...@@ -509,21 +614,21 @@ Flushes data in the cache to the file system so that the cached data can be acce
| Type | Description | | Type | Description |
| --------------------------------- | ------------------------------------- | | --------------------------------- | ------------------------------------- |
| Promise\<void>> | Promise used to return the result.| | Promise\<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
httpResponseCache.flush().then(() => { httpResponseCache.flush().then(() => {
console.log('flush success'); console.info('flush success');
}).catch(err => { }).catch(err => {
console.log('flush fail'); console.info('flush fail');
}); });
``` ```
### delete<sup>9+</sup> ### delete<sup>9+</sup>
delete(callback: AsyncCallback\<void>): void delete(callback: AsyncCallback\<void\>): void
Disables the cache and deletes the data in it. This API uses an asynchronous callback to return the result. 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 ...@@ -533,22 +638,22 @@ Disables the cache and deletes the data in it. This API uses an asynchronous cal
| Name | Type | Mandatory| Description | | Name | Type | Mandatory| Description |
| -------- | --------------------------------------- | ---- | ---------- | | -------- | --------------------------------------- | ---- | ---------- |
| callback | AsyncCallback\<void> | Yes | Callback used to return the result.| | callback | AsyncCallback\<void\> | Yes | Callback used to return the result.|
**Example** **Example**
```js ```js
httpResponseCache.delete(err => { httpResponseCache.delete(err => {
if (err) { if (err) {
console.log('delete fail'); console.info('delete fail');
return; return;
} }
console.log('delete success'); console.info('delete success');
}); });
``` ```
### delete<sup>9+</sup> ### delete<sup>9+</sup>
delete(): Promise\<void> delete(): Promise\<void\>
Disables the cache and deletes the data in it. This API uses a promise to return the result. 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 ...@@ -558,31 +663,18 @@ Disables the cache and deletes the data in it. This API uses a promise to return
| Type | Description | | Type | Description |
| --------------------------------- | ------------------------------------- | | --------------------------------- | ------------------------------------- |
| Promise\<void> | Promise used to return the result.| | Promise\<void\> | Promise used to return the result.|
**Example** **Example**
```js ```js
httpResponseCache.delete().then(() => { httpResponseCache.delete().then(() => {
console.log('delete success'); console.info('delete success');
}).catch(err => { }).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).
## HttpDataType<sup>9+</sup> ## HttpDataType<sup>9+</sup>
Enumerates HTTP data types. Enumerates HTTP data types.
...@@ -602,6 +694,6 @@ Enumerates HTTP protocol versions. ...@@ -602,6 +694,6 @@ Enumerates HTTP protocol versions.
**System capability**: SystemCapability.Communication.NetStack **System capability**: SystemCapability.Communication.NetStack
| Name | Description | | Name | Description |
| -------- | ----------- | | :-------- | :----------- |
| HTTP1_1 | HTTP1.1 | | HTTP1_1 | HTTP1.1 |
| HTTP2 | HTTP2 | | HTTP2 | HTTP2 |
...@@ -140,167 +140,6 @@ Obtains the default active data network in synchronous mode. You can use [getNet ...@@ -140,167 +140,6 @@ Obtains the default active data network in synchronous mode. You can use [getNet
let netHandle = connection.getDefaultNetSync(); let netHandle = connection.getDefaultNetSync();
``` ```
## connection.getGlobalHttpProxy<sup>10+</sup>
getGlobalHttpProxy(callback: AsyncCallback\<HttpProxy>): 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.getGlobalHttpProxy<sup>10+</sup>
getGlobalHttpProxy(): Promise\<HttpProxy>;
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.setGlobalHttpProxy<sup>10+</sup>
setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): 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\<void> | 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.setGlobalHttpProxy<sup>10+</sup>
setGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>;
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\<void> | 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.getAppNet<sup>9+</sup> ## connection.getAppNet<sup>9+</sup>
getAppNet(callback: AsyncCallback\<NetHandle>): void getAppNet(callback: AsyncCallback\<NetHandle>): void
...@@ -1823,18 +1662,6 @@ Enumerates network types. ...@@ -1823,18 +1662,6 @@ Enumerates network types.
| BEARER_WIFI | 1 | Wi-Fi network.| | BEARER_WIFI | 1 | Wi-Fi network.|
| BEARER_ETHERNET | 3 | Ethernet network.| | BEARER_ETHERNET | 3 | Ethernet network.|
## HttpProxy<sup>10+</sup>
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<string> | No | List of hosts that do not use the proxy server.|
## NetSpecifier ## NetSpecifier
Provides an instance that bears data network capabilities. Provides an instance that bears data network capabilities.
......
...@@ -2672,4 +2672,4 @@ Defines the certificate raw data. ...@@ -2672,4 +2672,4 @@ Defines the certificate raw data.
| Type | Description | | 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.|
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册