diff --git a/zh-cn/application-dev/connectivity/http-request.md b/zh-cn/application-dev/connectivity/http-request.md index 8c4c663fcc800a1998168aed065fd3e568a5e329..7bbd0e47bd06bb4e8ff51178224f02755cbd6447 100644 --- a/zh-cn/application-dev/connectivity/http-request.md +++ b/zh-cn/application-dev/connectivity/http-request.md @@ -18,17 +18,10 @@ HTTP数据请求功能主要由http模块提供。 | ----------------------------------------- | ----------------------------------- | | createHttp() | 创建一个http请求。 | | request() | 根据URL地址,发起HTTP网络请求。 | -| request2()10+ | 根据URL地址,发起HTTP网络请求并返回流式响应| | destroy() | 中断请求任务。 | | on(type: 'headersReceive') | 订阅HTTP Response Header 事件。 | | off(type: 'headersReceive') | 取消订阅HTTP Response Header 事件。 | | once\('headersReceive'\)8+ | 订阅HTTP Response Header 事件,但是只触发一次。| -| on\('dataReceive'\)10+ | 订阅HTTP流式响应数据接收事件。 | -| off\('dataReceive'\)10+ | 取消订阅HTTP流式响应数据接收事件。 | -| on\('dataEnd'\)10+ | 订阅HTTP流式响应数据接收完毕事件。 | -| off\('dataEnd'\)10+ | 取消订阅HTTP流式响应数据接收完毕事件。 | -| on\('dataProgress'\)10+ | 订阅HTTP流式响应数据接收进度事件。 | -| off\('dataProgress'\)10+ | 取消订阅HTTP流式响应数据接收进度事件。 | ## request接口开发步骤 @@ -70,7 +63,6 @@ httpRequest.request( connectTimeout: 60000, // 可选,默认为60000ms readTimeout: 60000, // 可选,默认为60000ms usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定 - usingProxy: false, //可选,默认不使用网络代理,自API 10开始支持该属性 }, (err, data) => { if (!err) { // data.result为HTTP响应内容,可根据业务需要进行解析 diff --git a/zh-cn/application-dev/reference/apis/js-apis-http.md b/zh-cn/application-dev/reference/apis/js-apis-http.md index afdc43e1e0896d996ac9512e096c6feef6666800..6fac1a2f1e58d0e4238614fd4cc9baa34e8fbb03 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-http.md +++ b/zh-cn/application-dev/reference/apis/js-apis-http.md @@ -45,7 +45,6 @@ httpRequest.request( connectTimeout: 60000, // 可选,默认为60000ms readTimeout: 60000, // 可选,默认为60000ms usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定 - usingProxy: false, //可选,默认不使用网络代理,自API 10开始支持该属性 }, (err, data) => { if (!err) { // data.result为HTTP响应内容,可根据业务需要进行解析 @@ -77,7 +76,7 @@ createHttp(): HttpRequest | 类型 | 说明 | | :---------- | :----------------------------------------------------------- | -| HttpRequest | 返回一个HttpRequest对象,里面包括request、request2、destroy、on和off方法。 | +| HttpRequest | 返回一个HttpRequest对象,里面包括request、destroy、on和off方法。 | **示例:** @@ -330,207 +329,6 @@ destroy(): void httpRequest.destroy(); ``` -### request210+ - -request2(url: string, callback: AsyncCallback\): void - -根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| callback | AsyncCallback\ | 是 | 回调函数。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 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. | - ->**错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:[curl错误码](https://curl.se/libcurl/c/libcurl-errors.html) - -**示例:** - -```js -httpRequest.request2("EXAMPLE_URL", (err) => { - if (!err) { - console.info("request2 OK!"); - } else { - console.info("request2 ERROR : err = " + JSON.stringify(err)); - } -}) -``` - -### request210+ - -request2(url: string, options: HttpRequestOptions, callback: AsyncCallback\): void - -根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| options | HttpRequestOptions | 是 | 参考[HttpRequestOptions](#httprequestoptions)。 | -| callback | AsyncCallback\ | 是 | 回调函数。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 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. | - ->**错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:[curl错误码](https://curl.se/libcurl/c/libcurl-errors.html) - -**示例:** - -```js -httpRequest.request2("EXAMPLE_URL", -{ - method: http.RequestMethod.GET, - header: { - 'Content-Type': 'application/json' - }, - readTimeout: 60000, - connectTimeout: 60000 -}, (err) => { - if (!err) { - console.info("request2 OK!"); - } else { - console.info("request2 ERROR : err = " + JSON.stringify(err)); - } -}) -``` -### request210+ - -request2(url: string, options? : HttpRequestOptions): Promise\ - -根据URL地址,发起HTTP网络请求并返回流式响应,使用Promise方式作为异步方法。 - -**需要权限**:ohos.permission.INTERNET - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| ------- | ------------------ | ---- | ----------------------------------------------- | -| url | string | 是 | 发起网络请求的URL地址。 | -| options | HttpRequestOptions | 否 | 参考[HttpRequestOptions](#httprequestoptions)。 | - -**返回值:** - -| 类型 | 说明 | -| :------------------------------------- | :-------------------------------- | -| Promise\ | 以Promise形式返回发起请求的结果。 | - -**错误码:** - -| 错误码ID | 错误信息 | -|---------|-------------------------------------------------------| -| 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. | - ->**错误码说明:** -> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。 -> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考: - -**示例:** - -```js -let promise = httpRequest.request("EXAMPLE_URL", { - method: http.RequestMethod.GET, - connectTimeout: 60000, - readTimeout: 60000, - header: { - 'Content-Type': 'application/json' - } -}); -promise.then(() => { - console.info("request2 OK!"); -}).catch((err) => { - console.info("request2 ERROR : err = " + JSON.stringify(err)); -}); ``` ### on('headerReceive') @@ -655,146 +453,7 @@ httpRequest.once('headersReceive', (header) => { console.info('header: ' + JSON.stringify(header)); }); ``` -### on('dataReceive')10+ - -on(type: 'dataReceive', callback: Callback\): void - -订阅HTTP流式响应数据接收事件。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | --------------------------------- | -| type | string | 是 | 订阅的事件类型,'dataReceive'。 | -| callback | AsyncCallback\ | 是 | 回调函数。 | - -**示例:** - -```js -httpRequest.on('dataReceive', (data) => { - console.info('dataReceive length: ' + JSON.stringify(data.byteLength)); -}); -``` - -### off('dataReceive')10+ - -off(type: 'dataReceive', callback?: Callback\): void - -取消订阅HTTP流式响应数据接收事件。 - ->**说明:** ->可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------ | ---- | -------------------------------------- | -| type | string | 是 | 取消订阅的事件类型:'dataReceive'。 | -| callback | Callback\ | 否 | 回调函数。 | - -**示例:** - -```js -httpRequest.off('dataReceive'); -``` - -### on('dataEnd')10+ - -on(type: 'dataEnd', callback: Callback\): void - -订阅HTTP流式响应数据接收完毕事件。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | --------------------------------- | -| type | string | 是 | 订阅的事件类型,'dataEnd'。 | -| callback | AsyncCallback\ | 是 | 回调函数。 | - -**示例:** - -```js -httpRequest.on('dataReceive', () => { - console.info('Receive dataEnd!'); -}); -``` -### off('dataEnd')10+ - -off(type: 'dataEnd', callback?: Callback\): void - -取消订阅HTTP流式响应数据接收完毕事件。 - ->**说明:** ->可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------ | ---- | -------------------------------------- | -| type | string | 是 | 取消订阅的事件类型:'dataEnd'。 | -| callback | Callback\ | 否 | 回调函数。 | - -**示例:** - -```js -httpRequest.off('dataEnd'); -``` - -### on('dataProgress')10+ - - on(type: 'dataProgress', callback: Callback\<{ receiveSize: number, totalSize: number }\>): void - -订阅HTTP流式响应数据接收进度事件。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ----------------------- | ---- | --------------------------------- | -| type | string | 是 | 订阅的事件类型,'dataProgress'。 | -| callback | AsyncCallback\<{ receiveSize: number, totalSize: number }\> | 是 | 回调函数。
receiveSize:已接收的数据字节数,totalSize待接收的字节总数 | - -**示例:** - -```js -httpRequest.on('dataProgress', (data) => { - console.info('dataProgress:' + JSON.stringify(data)); -}); -``` - -### off('dataProgress')10+ - -off(type: 'dataProgress', callback?: Callback\<{ receiveSize: number, totalSize: number }\>): void - -取消订阅HTTP流式响应数据接收进度事件。 - ->**说明:** ->可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 - -**系统能力**:SystemCapability.Communication.NetStack - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| -------- | ------------------ | ---- | -------------------------------------- | -| type | string | 是 | 取消订阅的事件类型:'dataProgress'。 | -| callback | Callback\<{ receiveSize: number, totalSize: number }\> | 否 | 回调函数。 | - -**示例:** - -```js -httpRequest.off('dataProgress'); -``` ## HttpRequestOptions 发起请求可选参数的类型和取值范围。 @@ -812,7 +471,6 @@ httpRequest.off('dataProgress'); | readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 | | connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 | | usingProtocol9+ | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 | -| usingProxy10+ | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。
- 当usingProxy为布尔类型true时,使用默认网络代理。
- 当usingProxy为object类型时,使用指定网络代理。 | ## RequestMethod diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-connection.md b/zh-cn/application-dev/reference/apis/js-apis-net-connection.md index 40492367bd96e8ebdb15bac7a4ba24d07346d0b1..254046cd7ba5e3618d475708d1b3952665081532 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-connection.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-connection.md @@ -140,167 +140,6 @@ getDefaultNetSync(): NetHandle let netHandle = connection.getDefaultNetSync(); ``` -## connection.getGlobalHttpProxy10+ - -getGlobalHttpProxy(callback: AsyncCallback\): void - -获取网络的全局代理配置信息,使用callback方式作为异步方法。 - -**系统接口**:此接口为系统接口。 - -**系统能力**:SystemCapability.Communication.NetManager.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| callback | AsyncCallback\<[HttpProxy](#httpproxy)> | 是 | 回调函数。当成功获取网络的全局代理配置信息时,err为undefined,data为网络的全局代理配置信息;否则为错误对象| - -**错误码:** - -| 错误码ID | 错误信息 | -| ------- | ----------------------------- | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**示例:** - -```js -connection.getGlobalHttpProxy((error,data) => { - console.info(JSON.stringify(error)); - console.info(JSON.stringify(data)); -}) -``` - -## connection.getGlobalHttpProxy10+ - -getGlobalHttpProxy(): Promise\; - -获取网络的全局代理配置信息,使用Promise方式作为异步方法。 - -**系统接口**:此接口为系统接口。 - -**系统能力**:SystemCapability.Communication.NetManager.Core - -**返回值:** - -| 类型 | 说明 | -| --------------------------------- | ------------------------------------- | -| Promise\<[HttpProxy](#httpproxy)> | 以Promise形式返回网络的全局代理配置信息。 | - -**错误码:** - -| 错误码ID | 错误信息 | -| ------- | ----------------------------- | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**示例:** - -```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 - -设置网络全局Http代理配置信息,使用callback方式作为异步方法。 - -**系统接口**:此接口为系统接口。 - -**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL - -**系统能力**:SystemCapability.Communication.NetManager.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| httpProxy | [HttpProxy](#httpproxy) | 是 | 网络全局Http代理配置信息 | -| callback | AsyncCallback\ | 是 | 回调函数。当成功设置网络全局Http代理配置信息时,err为undefined,否则为错误对象| - -**错误码:** - -| 错误码ID | 错误信息 | -| ------- | ----------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | -| 2100001 | Invalid parameter value. | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**示例:** - -```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\; - -设置网络全局Http代理配置信息,使用Promise方式作为异步方法。 - -**系统接口**:此接口为系统接口。 - -**需要权限**:ohos.permission.CONNECTIVITY_INTERNAL - -**系统能力**:SystemCapability.Communication.NetManager.Core - -**参数:** - -| 参数名 | 类型 | 必填 | 说明 | -| --------- | ------------------------------------------------------------ | ---- | ---------------- | -| httpProxy | [HttpProxy](#httpproxy) | 是 | 网络全局Http代理配置信息。 | - -**返回值:** - -| 类型 | 说明 | -| ------------------------------------------- | ----------------------------- | -| Promise\ | 无返回值的Promise对象。 | - -**错误码:** - -| 错误码ID | 错误信息 | -| ------- | ----------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | -| 2100001 | Invalid parameter value. | -| 2100002 | Operation failed. Cannot connect to service.| -| 2100003 | System internal error. | - -**示例:** - -```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(() => { - console.info("success"); -}).catch(error=>{ - console.info(JSON.stringify(error)); -}) -``` - ## connection.getAppNet9+ getAppNet(callback: AsyncCallback\): void @@ -1823,18 +1662,6 @@ connection.getDefaultNet().then(function (netHandle) { | BEARER_WIFI | 1 | Wi-Fi网络。 | | BEARER_ETHERNET | 3 | 以太网网络。 | -## HttpProxy10+ - -网络全局代理配置信息 - -**系统能力**:SystemCapability.Communication.NetManager.Core - -| 名称 | 类型 | 必填 | 说明 | -| ------ | ------ | --- |------------------------- | -| host | string | 否 | 代理服务器主机名。 | -| port | number | 否 | 主机端口。 | -| exclusionList | Array | 否 | 不使用代理服务器的屏蔽列表。 | - ## NetSpecifier 提供承载数据网络能力的实例。