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 c593449449deaf19aae6c75fb437a4b1d5a7bd95..bf34a19c164df7be8f46b16ccb2d098e7d6be575 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-http.md +++ b/zh-cn/application-dev/reference/apis/js-apis-http.md @@ -46,6 +46,7 @@ httpRequest.request( readTimeout: 60000, // 可选,默认为60000ms usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定 usingProxy: false, //可选,默认不使用网络代理,自API 10开始支持该属性 + caPath: "", // 可选,默认使用系统预设CA证书,自API 10开始支持该属性 }, (err, data) => { if (!err) { // data.result为HTTP响应内容,可根据业务需要进行解析 @@ -68,7 +69,7 @@ httpRequest.request( > **说明:** > console.info()输出的数据中包含换行符会导致数据出现截断现象。 -## http.createHttp +## http.createHttp6+ createHttp(): HttpRequest @@ -94,7 +95,7 @@ let httpRequest = http.createHttp(); HTTP请求任务。在调用HttpRequest的方法前,需要先通过[createHttp()](#httpcreatehttp)创建一个任务。 -### request +### request6+ request(url: string, callback: AsyncCallback\):void @@ -120,10 +121,34 @@ request(url: string, callback: AsyncCallback\):void |---------|-------------------------------------------------------| | 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. | > **错误码说明:** @@ -145,7 +170,7 @@ httpRequest.request("EXAMPLE_URL", (err, data) => { }); ``` -### request +### request6+ request(url: string, options: HttpRequestOptions, callback: AsyncCallback\):void @@ -231,7 +256,7 @@ httpRequest.request("EXAMPLE_URL", }); ``` -### request +### request6+ request(url: string, options? : HttpRequestOptions): Promise\ @@ -357,10 +382,34 @@ request2(url: string, callback: AsyncCallback\): void |---------|-------------------------------------------------------| | 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. | > **错误码说明:** @@ -757,7 +806,7 @@ httpRequest.off('dataEnd'); ### on('dataProgress')10+ -on(type: 'dataProgress', callback: AsyncCallback\<{ receiveSize: number, totalSize: number }\>): void +on(type: 'dataProgress', callback: Callback\<{ receiveSize: number, totalSize: number }\>): void 订阅HTTP流式响应数据接收进度事件。 @@ -802,7 +851,7 @@ off(type: 'dataProgress', callback?: Callback\<{ receiveSize: number, totalSize: httpRequest.off('dataProgress'); ``` -## HttpRequestOptions +## HttpRequestOptions6+ 发起请求可选参数的类型和取值范围。 @@ -819,9 +868,10 @@ httpRequest.off('dataProgress'); | readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。
设置为0表示不会出现超时情况。 | | connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 | | usingProtocol9+ | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 | -| usingProxy10+ | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。
- 当usingProxy为布尔类型true时,使用默认网络代理。
- 当usingProxy为object类型时,使用指定网络代理。 | +| usingProxy10+ | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。
- 当usingProxy为布尔类型true时,使用默认网络代理。
- 当usingProxy为object类型时,使用指定网络代理。 +| caPath10+ | string | 否 | 如果设置了此参数,系统将使用用户指定路径的CA证书,否则将使用系统预设CA证书。 | -## RequestMethod +## RequestMethod6+ HTTP 请求方法。 @@ -838,7 +888,7 @@ HTTP 请求方法。 | TRACE | "TRACE" | HTTP 请求 TRACE。 | | CONNECT | "CONNECT" | HTTP 请求 CONNECT。 | -## ResponseCode +## ResponseCode6+ 发起请求返回的响应码。 @@ -882,7 +932,7 @@ HTTP 请求方法。 | GATEWAY_TIMEOUT | 504 | 充当网关或代理的服务器,未及时从远端服务器获取请求。 | | VERSION | 505 | 服务器请求的HTTP协议的版本。 | -## HttpResponse +## HttpResponse6+ request方法回调函数的返回值类型。 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 555f84dcd7bee39b84e68a8b45730a36d06e4867..c395e6ed79b54e8c937f0ea03e31e1350a30c27c 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 @@ -11,7 +11,7 @@ import connection from '@ohos.net.connection' ``` -## connection.createNetConnection +## connection.createNetConnection8+ createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection @@ -46,7 +46,7 @@ let netConnectionCellular = connection.createNetConnection({ }) ``` -## connection.getDefaultNet +## connection.getDefaultNet8+ getDefaultNet(callback: AsyncCallback\): void @@ -79,7 +79,7 @@ connection.getDefaultNet(function (error, data) { }) ``` -## connection.getDefaultNet +## connection.getDefaultNet8+ getDefaultNet(): Promise\ @@ -444,7 +444,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## connection.getAllNets +## connection.getAllNets8+ getAllNets(callback: AsyncCallback<Array<NetHandle>>): void @@ -477,7 +477,7 @@ connection.getAllNets(function (error, data) { }); ``` -## connection.getAllNets +## connection.getAllNets8+ getAllNets(): Promise<Array<NetHandle>> @@ -509,7 +509,7 @@ connection.getAllNets().then(function (data) { }); ``` -## connection.getConnectionProperties +## connection.getConnectionProperties8+ getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback\): void @@ -547,7 +547,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## connection.getConnectionProperties +## connection.getConnectionProperties8+ getConnectionProperties(netHandle: NetHandle): Promise\ @@ -589,7 +589,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## connection.getNetCapabilities +## connection.getNetCapabilities8+ getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback\): void @@ -627,7 +627,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## connection.getNetCapabilities +## connection.getNetCapabilities8+ getNetCapabilities(netHandle: NetHandle): Promise\ @@ -734,7 +734,7 @@ connection.isDefaultNetMetered().then(function (data) { }) ``` -## connection.hasDefaultNet +## connection.hasDefaultNet8+ hasDefaultNet(callback: AsyncCallback\): void @@ -767,7 +767,7 @@ connection.hasDefaultNet(function (error, data) { }) ``` -## connection.hasDefaultNet +## connection.hasDefaultNet8+ hasDefaultNet(): Promise\ @@ -799,7 +799,7 @@ connection.hasDefaultNet().then(function (data) { }) ``` -## connection.enableAirplaneMode +## connection.enableAirplaneMode8+ enableAirplaneMode(callback: AsyncCallback\): void @@ -821,6 +821,7 @@ enableAirplaneMode(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | ----------------------------- | +| 202 | Non-system applications use system APIs.| | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | @@ -832,7 +833,7 @@ connection.enableAirplaneMode(function (error) { }) ``` -## connection.enableAirplaneMode +## connection.enableAirplaneMode8+ enableAirplaneMode(): Promise\ @@ -854,6 +855,7 @@ enableAirplaneMode(): Promise\ | 错误码ID | 错误信息 | | ------- | ----------------------------- | +| 202 | Non-system applications use system APIs.| | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | @@ -865,7 +867,7 @@ connection.enableAirplaneMode().then(function (error) { }) ``` -## connection.disableAirplaneMode +## connection.disableAirplaneMode8+ disableAirplaneMode(callback: AsyncCallback\): void @@ -887,6 +889,7 @@ disableAirplaneMode(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | ----------------------------- | +| 202 | Non-system applications use system APIs.| | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | @@ -898,7 +901,7 @@ connection.disableAirplaneMode(function (error) { }) ``` -## connection.disableAirplaneMode +## connection.disableAirplaneMode8+ disableAirplaneMode(): Promise\ @@ -920,6 +923,7 @@ disableAirplaneMode(): Promise\ | 错误码ID | 错误信息 | | ------- | ----------------------------- | +| 202 | Non-system applications use system APIs.| | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | @@ -931,7 +935,7 @@ connection.disableAirplaneMode().then(function (error) { }) ``` -## connection.reportNetConnected +## connection.reportNetConnected8+ reportNetConnected(netHandle: NetHandle, callback: AsyncCallback<void>): void @@ -968,7 +972,7 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` -## connection.reportNetConnected +## connection.reportNetConnected8+ reportNetConnected(netHandle: NetHandle): Promise<void> @@ -1009,7 +1013,7 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` -## connection.reportNetDisconnected +## connection.reportNetDisconnected8+ reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void @@ -1046,7 +1050,7 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` -## connection.reportNetDisconnected +## connection.reportNetDisconnected8+ reportNetDisconnected(netHandle: NetHandle): Promise<void> @@ -1087,7 +1091,7 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` -## connection.getAddressesByName +## connection.getAddressesByName8+ getAddressesByName(host: string, callback: AsyncCallback\>): void @@ -1124,7 +1128,7 @@ connection.getAddressesByName(host, function (error, data) { }) ``` -## connection.getAddressesByName +## connection.getAddressesByName8+ getAddressesByName(host: string): Promise\> @@ -1174,7 +1178,7 @@ connection.getAddressesByName(host).then(function (data) { > 设备从有网络到无网络状态会触发netLost事件; > 设备从WiFi到蜂窝会触发netLost事件(WiFi丢失)之后触发 netAvaliable事件(蜂窝可用); -### register +### register8+ register(callback: AsyncCallback\): void @@ -1195,9 +1199,10 @@ register(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | ----------------------------- | | 201 | Permission denied. | +| 401 | Parameter error. | | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | -| 2101008 | The callback is not exists. | +| 2101008 | The callback is not found. | | 2101022 | The number of requests exceeded the maximum. | **示例:** @@ -1208,7 +1213,7 @@ netConnection.register(function (error) { }) ``` -### unregister +### unregister8+ unregister(callback: AsyncCallback\): void @@ -1226,9 +1231,11 @@ unregister(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | ----------------------------- | +| 201 | Permission denied.| +| 401 | Parameter error. | | 2100002 | Operation failed. Cannot connect to service.| | 2100003 | System internal error. | -| 2101007 | The same callback exists. | +| 2100207 | Remote is null. | **示例:** @@ -1238,7 +1245,7 @@ netConnection.unregister(function (error) { }) ``` -### on('netAvailable') +### on('netAvailable')8+ on(type: 'netAvailable', callback: Callback\): void @@ -1277,7 +1284,7 @@ netCon.unregister(function (error) { }) ``` -### on('netBlockStatusChange') +### on('netBlockStatusChange')8+ on(type: 'netBlockStatusChange', callback: Callback<{ netHandle: NetHandle, blocked: boolean }>): void @@ -1316,7 +1323,7 @@ netCon.unregister(function (error) { }) ``` -### on('netCapabilitiesChange') +### on('netCapabilitiesChange')8+ on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void @@ -1355,7 +1362,7 @@ netCon.unregister(function (error) { }) ``` -### on('netConnectionPropertiesChange') +### on('netConnectionPropertiesChange')8+ on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties: ConnectionProperties }>): void @@ -1395,7 +1402,7 @@ netCon.unregister(function (error) { }) ``` -### on('netLost') +### on('netLost')8+ on(type: 'netLost', callback: Callback\): void @@ -1434,7 +1441,7 @@ netCon.unregister(function (error) { }) ``` -### on('netUnavailable') +### on('netUnavailable')8+ on(type: 'netUnavailable', callback: Callback\): void @@ -1473,7 +1480,7 @@ netCon.unregister(function (error) { }) ``` -## NetHandle +## NetHandle8+ 数据网络的句柄。 @@ -1640,7 +1647,7 @@ connection.getDefaultNet().then((netHandle) => { }) ``` -### getAddressesByName +### getAddressesByName8+ getAddressesByName(host: string, callback: AsyncCallback\>): void @@ -1679,7 +1686,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -### getAddressesByName +### getAddressesByName8+ getAddressesByName(host: string): Promise\> @@ -1722,7 +1729,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -### getAddressByName +### getAddressByName8+ getAddressByName(host: string, callback: AsyncCallback\): void @@ -1761,7 +1768,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -### getAddressByName +### getAddressByName8+ getAddressByName(host: string): Promise\ @@ -1804,7 +1811,7 @@ connection.getDefaultNet().then(function (netHandle) { }) ``` -## NetCap +## NetCap8+ 网络具体能力。 @@ -1818,7 +1825,7 @@ connection.getDefaultNet().then(function (netHandle) { | NET_CAPABILITY_NOT_VPN | 15 | 表示网络不使用VPN(Virtual Private Network,虚拟专用网络)。 | | NET_CAPABILITY_VALIDATED | 16 | 表示该网络访问Internet的能力被网络管理成功验证,该能力由网络管理模块设置。 | -## NetBearType +## NetBearType8+ 网络类型。 @@ -1842,7 +1849,7 @@ connection.getDefaultNet().then(function (netHandle) { | port | number | 否 | 主机端口。 | | exclusionList | Array | 否 | 不使用代理服务器的屏蔽列表,列表内元素拼接后长度不可超过96字节。
例如:“baidu.com,zhihu.com”为20字节。 | -## NetSpecifier +## NetSpecifier8+ 提供承载数据网络能力的实例。 @@ -1853,7 +1860,7 @@ connection.getDefaultNet().then(function (netHandle) { | netCapabilities | [NetCapabilities](#netcapabilities) | 是 | 存储数据网络的传输能力和承载类型。 | | bearerPrivateIdentifier | string | 否 | 网络标识符,Wi-Fi网络的标识符是"wifi",蜂窝网络的标识符是"slot0"(对应SIM卡1)。 | -## NetCapabilities +## NetCapabilities8+ 网络的能力集。 @@ -1866,7 +1873,7 @@ connection.getDefaultNet().then(function (netHandle) { | networkCap | Array\<[NetCap](#netcap)> | 否 | 网络具体能力。 | | bearerTypes | Array\<[NetBearType](#netbeartype)> | 是 | 网络类型。 | -## ConnectionProperties +## ConnectionProperties8+ 网络连接信息。 @@ -1881,7 +1888,7 @@ connection.getDefaultNet().then(function (netHandle) { | dnses | Array\<[NetAddress](#netaddress)> | 是 |网络地址,参考[NetAddress](#netaddress)。 | | mtu | number | 是 |最大传输单元。 | -## RouteInfo +## RouteInfo8+ 网络路由信息。 @@ -1895,7 +1902,7 @@ connection.getDefaultNet().then(function (netHandle) { | hasGateway | boolean | 是 |是否有网关。 | | isDefaultRoute | boolean | 是 |是否为默认路由。 | -## LinkAddress +## LinkAddress8+ 网络链路信息。 @@ -1906,7 +1913,7 @@ connection.getDefaultNet().then(function (netHandle) { | address | [NetAddress](#netaddress) | 是 | 链路地址。 | | prefixLength | number | 是 |链路地址前缀的长度。 | -## NetAddress +## NetAddress8+ 网络地址。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md b/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md index a06d898425281376385620242a8b614190169d07..4f32881ab608cdefb54f1f9fef5119e42a052fa0 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md @@ -11,7 +11,7 @@ import ethernet from '@ohos.net.ethernet' ``` -## ethernet.setIfaceConfig +## ethernet.setIfaceConfig9+ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\): void @@ -36,13 +36,15 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallbac | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | -| 2201006 | Device disconnected. | -| 2201007 | Failed to write the user configuration. | +| 2201004 | Invalid Ethernet profile. | +| 2201005 | Device information does not exist. | +| 2201006 | Ethernet device not connected. | +| 2201007 | Ethernet failed to write user configuration information. | **示例:** @@ -64,7 +66,7 @@ ethernet.setIfaceConfig("eth0", { }); ``` -## ethernet.setIfaceConfig +## ethernet.setIfaceConfig9+ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\ @@ -94,13 +96,15 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\ | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | -| 2201006 | Device disconnected. | -| 2201007 | Failed to write the user configuration. | +| 2201004 | Invalid Ethernet profile. | +| 2201005 | Device information does not exist. | +| 2201006 | Ethernet device not connected. | +| 2201007 | Ethernet failed to write user configuration information. | **示例:** @@ -120,7 +124,7 @@ ethernet.setIfaceConfig("eth0", { }); ``` -## ethernet.getIfaceConfig +## ethernet.getIfaceConfig9+ getIfaceConfig(iface: string, callback: AsyncCallback\): void @@ -144,11 +148,12 @@ getIfaceConfig(iface: string, callback: AsyncCallback\): | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | +| 2201005 | Device information does not exist. | **示例:** @@ -168,7 +173,7 @@ ethernet.getIfaceConfig("eth0", (error, value) => { }); ``` -## ethernet.getIfaceConfig +## ethernet.getIfaceConfig9+ getIfaceConfig(iface: string): Promise\ @@ -197,11 +202,12 @@ getIfaceConfig(iface: string): Promise\ | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | +| 2201005 | Device information does not exist. | **示例:** @@ -219,7 +225,7 @@ ethernet.getIfaceConfig("eth0").then((data) => { }); ``` -## ethernet.isIfaceActive +## ethernet.isIfaceActive9+ isIfaceActive(iface: string, callback: AsyncCallback\): void @@ -243,11 +249,12 @@ isIfaceActive(iface: string, callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | +| 2201005 | Device information does not exist. | **示例:** @@ -261,7 +268,7 @@ ethernet.isIfaceActive("eth0", (error, value) => { }); ``` -## ethernet.isIfaceActive +## ethernet.isIfaceActive9+ isIfaceActive(iface: string): Promise\ @@ -290,11 +297,12 @@ isIfaceActive(iface: string): Promise\ | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | -| 2201005 | The device information does not exist. | +| 2201005 | Device information does not exist. | **示例:** @@ -306,7 +314,7 @@ ethernet.isIfaceActive("eth0").then((data) => { }); ``` -## ethernet.getAllActiveIfaces +## ethernet.getAllActiveIfaces9+ getAllActiveIfaces(callback: AsyncCallback\>): void @@ -329,6 +337,7 @@ getAllActiveIfaces(callback: AsyncCallback\>): void | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | @@ -347,7 +356,7 @@ ethernet.getAllActiveIfaces((error, value) => { }); ``` -## ethernet.getAllActiveIfaces +## ethernet.getAllActiveIfaces9+ getAllActiveIfaces(): Promise\> @@ -370,6 +379,7 @@ getAllActiveIfaces(): Promise\> | 错误码ID | 错误信息 | | ------- | ----------------------------------------| | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 2200002 | Operation failed. Cannot connect to service.| | 2200003 | System internal error. | @@ -403,21 +413,19 @@ on(type: 'interfaceStateChange', callback: Callback\<{ iface: string, active: bo | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------- | ---- | ---------- | | type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 | -| callback | Callback\<{ iface: string, active: boolean }\> | 是 | 回调函数。
iface:网卡名称。
active:是否处于激活状态(true:激活;false:未激活) | +| callback | AsyncCallback\<{ iface: string, active: boolean }\> | 是 | 回调函数。
iface:网卡名称。
active:是否处于激活状态(true:激活;false:未激活) | **错误码:** | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 202 | Applicable only to system applications. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** ```js -ethernet.on('interfaceStateChange', (data) => { - console.log('on interfaceSharingStateChange:' + JSON.stringify(data.iface) + JSON.stringify(data.active)); + ethernet.on('interfaceStateChange', (data) => { + console.log('on interfaceSharingStateChange:' + JSON.stringify(data)); }); ``` @@ -438,15 +446,13 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active: | 参数名 | 类型 | 必填 | 说明 | | -------- | --------------------------------------- | ---- | ---------- | | type | string | 是 | 订阅的事件类型,'interfaceStateChange'。 | -| callback | Callback\<{ iface: string, active: boolean }> | 否 | 回调函数。
iface:网卡名称。
active:是否处于激活状态(true:激活;false:未激活) | +| callback | AsyncCallback\<{ iface: string, active: boolean }> | 否 | 回调函数。
iface:网卡名称。
active:是否处于激活状态(true:激活;false:未激活) | **错误码:** | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 202 | Applicable only to system applications. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -454,7 +460,7 @@ off(type: 'interfaceStateChange', callback?: Callback\<{ iface: string, active: ethernet.off('interfaceStateChange'); ``` -## InterfaceConfiguration +## InterfaceConfiguration9+ 以太网连接配置网络信息。 @@ -471,7 +477,7 @@ ethernet.off('interfaceStateChange'); | netMask | string | 是 | 以太网连接配置子网掩码,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)。 | | dnsServers | string | 是 | 以太网连接配置dns服务地址,地址值范围0-255.0-255.0-255.0-255(DHCP模式无需配置)多地址间用“,”隔开。 | -## IPSetMode +## IPSetMode9+ 以太网连接模式。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-mdns.md b/zh-cn/application-dev/reference/apis/js-apis-net-mdns.md index 4ddf1deca564c3302ab92a06c625e5332b50fea7..cf4b2ffb92c380b1566f0207a220d20da6c4df4d 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-mdns.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-mdns.md @@ -11,7 +11,7 @@ MDNS即多播DNS(Multicast DNS),提供局域网内的本地服务添加、 import mdns from '@ohos.net.mdns' ``` -## mdns.addLocalService +## mdns.addLocalService10+ addLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\): void @@ -100,7 +100,7 @@ mdns.addLocalService(context, localServiceInfo, function (error, data) { }); ``` -## mdns.addLocalService +## mdns.addLocalService10+ addLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\ @@ -192,7 +192,7 @@ mdns.addLocalService(context, localServiceInfo).then(function (data) { }); ``` -## mdns.removeLocalService +## mdns.removeLocalService10+ removeLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\): void @@ -216,7 +216,7 @@ removeLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: As | 2100002 | Operation failed. Cannot connect to service. | | 2100003 | System internal error. | | 2204002 | Callback not found. | -| 2204008 | Service instance duplicated. | +| 2204008 | Service instance not found. | | 2204010 | Send packet failed. | > **错误码说明:** @@ -281,7 +281,7 @@ mdns.removeLocalService(context, localServiceInfo, function (error, data) { }); ``` -## mdns.removeLocalService +## mdns.removeLocalService10+ removeLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\ @@ -310,7 +310,7 @@ removeLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\ **错误码说明:** @@ -373,7 +373,7 @@ mdns.removeLocalService(context, localServiceInfo).then(function (data) { }); ``` -## mdns.createDiscoveryService +## mdns.createDiscoveryService10+ createDiscoveryService(context: Context, serviceType: string): DiscoveryService @@ -423,7 +423,7 @@ let serviceType = "_print._tcp"; let discoveryService = mdns.createDiscoveryService(context, serviceType); ``` -## mdns.resolveLocalService +## mdns.resolveLocalService10+ resolveLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\): void @@ -512,7 +512,7 @@ mdns.resolveLocalService(context, localServiceInfo, function (error, data) { }); ``` -## mdns.resolveLocalService +## mdns.resolveLocalService10+ resolveLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\ @@ -603,11 +603,11 @@ mdns.resolveLocalService(context, localServiceInfo).then(function (data) { console.log(JSON.stringify(data)); }); ``` -## DiscoveryService +## DiscoveryService10+ 指定服务类型的发现服务对象。 -### startSearchingMDNS +### startSearchingMDNS10+ startSearchingMDNS(): void @@ -644,7 +644,7 @@ let discoveryService = mdns.createDiscoveryService(context, serviceType); discoveryService.startSearchingMDNS(); ``` -### stopSearchingMDNS +### stopSearchingMDNS10+ stopSearchingMDNS(): void @@ -681,7 +681,7 @@ let discoveryService = mdns.createDiscoveryService(context, serviceType); discoveryService.stopSearchingMDNS(); ``` -### on('discoveryStart') +### on('discoveryStart')10+ on(type: 'discoveryStart', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void @@ -710,7 +710,7 @@ discoveryService.on('discoveryStart', (data) => { discoveryService.stopSearchingMDNS(); ``` -### on('discoveryStop') +### on('discoveryStop')10+ on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void @@ -739,7 +739,7 @@ discoveryService.on('discoveryStop', (data) => { discoveryService.stopSearchingMDNS(); ``` -### on('serviceFound') +### on('serviceFound')10+ on(type: 'serviceFound', callback: Callback\): void @@ -768,7 +768,7 @@ discoveryService.on('serviceFound', (data) => { discoveryService.stopSearchingMDNS(); ``` -### on('serviceLost') +### on('serviceLost')10+ on(type: 'serviceLost', callback: Callback\): void @@ -797,7 +797,7 @@ discoveryService.on('serviceLost', (data) => { discoveryService.stopSearchingMDNS(); ``` -## LocalServiceInfo +## LocalServiceInfo10+ mDNS服务信息 @@ -811,7 +811,7 @@ mDNS服务信息 | host | [NetAddress](js-apis-net-connection.md#netaddress) | 否 | mDNS服务设备的IP地址。采用设备的IP,添加服务和移除服务时候不生效。 | | serviceAttribute | serviceAttribute\<[ServiceAttribute](#serviceattribute)> | 否 | mDNS服务属性信息。 | -## ServiceAttribute +## ServiceAttribute10+ mDNS服务属性信息 diff --git a/zh-cn/application-dev/reference/apis/js-apis-net-sharing.md b/zh-cn/application-dev/reference/apis/js-apis-net-sharing.md index 0419052af8cd7c222d788f2f7c04bf020e7e3280..0dfb683919e0f331e2746b48b58a7070f899d48e 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-net-sharing.md +++ b/zh-cn/application-dev/reference/apis/js-apis-net-sharing.md @@ -12,7 +12,7 @@ import sharing from '@ohos.net.sharing' ``` -## sharing.isSharingSupported +## sharing.isSharingSupported9+ isSharingSupported(callback: AsyncCallback\): void @@ -48,7 +48,7 @@ sharing.isSharingSupported((error, data) => { }); ``` -## sharing.isSharingSupported +## sharing.isSharingSupported9+ isSharingSupported(): Promise\ @@ -85,7 +85,7 @@ sharing.isSharingSupported().then(data => { }); ``` -## sharing.isSharing +## sharing.isSharing9+ isSharing(callback: AsyncCallback\): void @@ -108,8 +108,10 @@ isSharing(callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 2200002 | Operation failed. Cannot connect to service. | | 2200003 | System internal error. | +| 2202011 | Cannot get network sharing configuration. | **示例:** @@ -120,7 +122,7 @@ sharing.isSharing((error, data) => { }); ``` -## sharing.isSharing +## sharing.isSharing9+ isSharing(): Promise\ @@ -143,8 +145,10 @@ isSharing(): Promise\ | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 2200002 | Operation failed. Cannot connect to service. | | 2200003 | System internal error. | +| 2202011 | Cannot get network sharing configuration. | **示例:** @@ -156,7 +160,7 @@ sharing.isSharing().then(data => { }); ``` -## sharing.startSharing +## sharing.startSharing9+ startSharing(type: SharingIfaceType, callback: AsyncCallback\): void @@ -201,7 +205,7 @@ sharing.startSharing(SHARING_WIFI, (error) => { }); ``` -## sharing.startSharing +## sharing.startSharing9+ startSharing(type: SharingIfaceType): Promise\ @@ -253,7 +257,7 @@ sharing.startSharing(SHARING_WIFI).then(() => { }); ``` -## sharing.stopSharing +## sharing.stopSharing9+ stopSharing(type: SharingIfaceType, callback: AsyncCallback\): void @@ -277,10 +281,12 @@ stopSharing(type: SharingIfaceType, callback: AsyncCallback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service. | | 2200003 | System internal error. | +| 2202004 | Try to share an unavailable iface. | | 2202005 | WiFi sharing failed. | | 2202006 | Bluetooth sharing failed. | | 2202011 | Cannot get network sharing configuration. | @@ -296,7 +302,7 @@ sharing.stopSharing(SHARING_WIFI, (error) => { }); ``` -## sharing.stopSharing +## sharing.stopSharing9+ stopSharing(type: SharingIfaceType): Promise\ @@ -325,10 +331,12 @@ stopSharing(type: SharingIfaceType): Promise\ | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | | 201 | Permission denied. | +| 202 | Non-system applications use system APIs. | | 401 | Parameter error. | | 2200001 | Invalid parameter value. | | 2200002 | Operation failed. Cannot connect to service. | | 2200003 | System internal error. | +| 2202004 | Try to share an unavailable iface. | | 2202005 | WiFi sharing failed. | | 2202006 | Bluetooth sharing failed. | | 2202011 | Cannot get network sharing configuration. | @@ -346,7 +354,7 @@ sharing.stopSharing(SHARING_WIFI).then(() => { }); ``` -## sharing.getStatsRxBytes +## sharing.getStatsRxBytes9+ getStatsRxBytes(callback: AsyncCallback\): void @@ -381,7 +389,7 @@ sharing.getStatsRxBytes((error, data) => { }); ``` -## sharing.getStatsRxBytes +## sharing.getStatsRxBytes9+ getStatsRxBytes(): Promise\ @@ -417,7 +425,7 @@ sharing.getStatsRxBytes().then(data => { }); ``` -## sharing.getStatsTxBytes +## sharing.getStatsTxBytes9+ getStatsTxBytes(callback: AsyncCallback\): void @@ -452,7 +460,7 @@ sharing.getStatsTxBytes((error, data) => { }); ``` -## sharing.getStatsTxBytes +## sharing.getStatsTxBytes9+ getStatsTxBytes(): Promise\ @@ -488,7 +496,7 @@ sharing.getStatsTxBytes().then(data => { }); ``` -## sharing.getStatsTotalBytes +## sharing.getStatsTotalBytes9+ getStatsTotalBytes(callback: AsyncCallback\): void @@ -523,7 +531,7 @@ sharing.getStatsTotalBytes((error, data) => { }); ``` -## sharing.getStatsTotalBytes +## sharing.getStatsTotalBytes9+ getStatsTotalBytes(): Promise\ @@ -559,7 +567,7 @@ sharing.getStatsTotalBytes().then(data => { }); ``` -## sharing.getSharingIfaces +## sharing.getSharingIfaces9+ getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\>): void @@ -600,7 +608,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH, (error, data) => { }); ``` -## sharing.getSharingIfaces +## sharing.getSharingIfaces9+ getSharingIfaces(state: SharingIfaceState): Promise\> @@ -647,7 +655,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH).then(data => { }); ``` -## sharing.getSharingState +## sharing.getSharingState9+ getSharingState(type: SharingIfaceType, callback: AsyncCallback\): void @@ -688,7 +696,7 @@ sharing.getSharingState(SHARING_WIFI, (error, data) => { }); ``` -## sharing.getSharingState +## sharing.getSharingState9+ getSharingState(type: SharingIfaceType): Promise\ @@ -735,7 +743,7 @@ sharing.getSharingState(SHARING_WIFI).then(data => { }); ``` -## sharing.getSharableRegexes +## sharing.getSharableRegexes9+ getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\>): void @@ -776,7 +784,7 @@ sharing.getSharableRegexes(SHARING_WIFI, (error, data) => { }); ``` -## sharing.getSharableRegexes +## sharing.getSharableRegexes9+ getSharableRegexes(type: SharingIfaceType): Promise\> @@ -823,7 +831,7 @@ sharing.getSharableRegexes(SHARING_WIFI).then(data => { }); ``` -## sharing.on('sharingStateChange') +## sharing.on('sharingStateChange')9+ on(type: 'sharingStateChange', callback: Callback\): void @@ -846,8 +854,7 @@ on(type: 'sharingStateChange', callback: Callback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -857,7 +864,7 @@ sharing.on('sharingStateChange', (data) => { }); ``` -## sharing.off('sharingStateChange') +## sharing.off('sharingStateChange')9+ off(type: 'sharingStateChange', callback?: Callback\): void @@ -880,8 +887,7 @@ off(type: 'sharingStateChange', callback?: Callback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -891,7 +897,7 @@ sharing.off('sharingStateChange', (data) => { }); ``` -## sharing.on('interfaceSharingStateChange') +## sharing.on('interfaceSharingStateChange')9+ on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -915,8 +921,7 @@ SharingIfaceState }>): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -926,7 +931,7 @@ sharing.on('interfaceSharingStateChange', (data) => { }); ``` -## sharing.off('interfaceSharingStateChange') +## sharing.off('interfaceSharingStateChange')9+ off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -950,8 +955,7 @@ SharingIfaceState }>): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -961,7 +965,7 @@ sharing.off('interfaceSharingStateChange', (data) => { }); ``` -## sharing.on('sharingUpstreamChange') +## sharing.on('sharingUpstreamChange')9+ on(type: 'sharingUpstreamChange', callback: Callback\): void @@ -984,8 +988,7 @@ on(type: 'sharingUpstreamChange', callback: Callback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -995,7 +998,7 @@ sharing.on('sharingUpstreamChange', (data) => { }); ``` -## sharing.off('sharingUpstreamChange') +## sharing.off('sharingUpstreamChange')9+ off(type: 'sharingUpstreamChange', callback?: Callback\): void @@ -1018,8 +1021,7 @@ off(type: 'sharingUpstreamChange', callback?: Callback\): void | 错误码ID | 错误信息 | | ------- | -------------------------------------------- | -| 201 | Permission denied. | -| 401 | Parameter error. | +| 202 | Non-system applications use system APIs. | **示例:** @@ -1029,7 +1031,7 @@ sharing.off('sharingUpstreamChange', (data) => { }); ``` -## SharingIfaceState +## SharingIfaceState9+ 网络共享状态。 @@ -1043,7 +1045,7 @@ sharing.off('sharingUpstreamChange', (data) => { | SHARING_NIC_CAN_SERVER | 2 | 可提供网络共享。 | | SHARING_NIC_ERROR | 3 | 网络共享错误。 | -## SharingIfaceType +## SharingIfaceType9+ 网络共享类型。 diff --git a/zh-cn/application-dev/reference/apis/js-apis-socket.md b/zh-cn/application-dev/reference/apis/js-apis-socket.md index a2ce8694da4d07eaea787cffd8bd426a7b513bb3..b0bf07ffeedfeb74fd1e1017168215b802ee1974 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-socket.md +++ b/zh-cn/application-dev/reference/apis/js-apis-socket.md @@ -12,7 +12,7 @@ import socket from '@ohos.net.socket'; ``` -## socket.constructUDPSocketInstance +## socket.constructUDPSocketInstance7+ constructUDPSocketInstance(): UDPSocket @@ -32,19 +32,16 @@ constructUDPSocketInstance(): UDPSocket let udp = socket.constructUDPSocketInstance(); ``` -## UDPSocket +## UDPSocket7+ UDPSocket连接。在调用UDPSocket的方法前,需要先通过[socket.constructUDPSocketInstance](#socketconstructudpsocketinstance)创建UDPSocket对象。 -### bind +### bind7+ bind(address: NetAddress, callback: AsyncCallback\): void 绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方式作为异步方法。 -> **说明:** -> 客户端使用该方法创建socket。 - **需要权限**:ohos.permission.INTERNET **系统能力**:SystemCapability.Communication.NetStack @@ -67,7 +64,7 @@ bind(address: NetAddress, callback: AsyncCallback\): void ```js let udp = socket.constructUDPSocketInstance(); -udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { +udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); return; @@ -76,15 +73,12 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { }) ``` -### bind +### bind7+ bind(address: NetAddress): Promise\ 绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方式作为异步方法。 -> **说明:** -> 客户端使用该方法创建socket。 - **需要权限**:ohos.permission.INTERNET **系统能力**:SystemCapability.Communication.NetStack @@ -120,7 +114,7 @@ promise.then(() => { }); ``` -### send +### send7+ send(options: UDPSendOptions, callback: AsyncCallback\): void @@ -166,7 +160,7 @@ udp.send({ }) ``` -### send +### send7+ send(options: UDPSendOptions): Promise\ @@ -216,7 +210,7 @@ promise.then(() => { }); ``` -### close +### close7+ close(callback: AsyncCallback\): void @@ -245,7 +239,7 @@ udp.close(err => { }) ``` -### close +### close7+ close(): Promise\ @@ -273,7 +267,7 @@ promise.then(() => { }); ``` -### getState +### getState7+ getState(callback: AsyncCallback\): void @@ -318,7 +312,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { }) ``` -### getState +### getState7+ getState(): Promise\ @@ -357,7 +351,7 @@ promise.then(err => { }); ``` -### setExtraOptions +### setExtraOptions7+ setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\): void @@ -410,7 +404,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { }) ``` -### setExtraOptions +### setExtraOptions7+ setExtraOptions(options: UDPExtraOptions): Promise\ @@ -466,7 +460,7 @@ promise.then(() => { }); ``` -### on('message') +### on('message')7+ on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void @@ -497,7 +491,7 @@ udp.on('message', value => { }); ``` -### off('message') +### off('message')7+ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void @@ -535,7 +529,7 @@ udp.off('message', callback); udp.off('message'); ``` -### on('listening' | 'close') +### on('listening' | 'close')7+ on(type: 'listening' | 'close', callback: Callback\): void @@ -562,7 +556,7 @@ udp.on('close', () => { }); ``` -### off('listening' | 'close') +### off('listening' | 'close')7+ off(type: 'listening' | 'close', callback?: Callback\): void @@ -600,7 +594,7 @@ udp.off('close', callback2); udp.off('close'); ``` -### on('error') +### on('error')7+ on(type: 'error', callback: ErrorCallback): void @@ -624,7 +618,7 @@ udp.on('error', err => { }); ``` -### off('error') +### off('error')7+ off(type: 'error', callback?: ErrorCallback): void @@ -655,7 +649,7 @@ udp.off('error', callback); udp.off('error'); ``` -## NetAddress +## NetAddress7+ 目标地址信息。 @@ -667,7 +661,7 @@ udp.off('error'); | port | number | 否 | 端口号 ,范围0~65535。如果不指定系统随机分配端口。 | | family | number | 否 | 网络协议类型,可选类型:
- 1:IPv4
- 2:IPv6
默认为1。 | -## UDPSendOptions +## UDPSendOptions7+ UDPSocket发送参数。 @@ -678,7 +672,7 @@ UDPSocket发送参数。 | data | string \| ArrayBuffer7+ | 是 | 发送的数据。 | | address | [NetAddress](#netaddress) | 是 | 目标地址信息。 | -## UDPExtraOptions +## UDPExtraOptions7+ UDPSocket连接的其他属性。 @@ -692,7 +686,7 @@ UDPSocket连接的其他属性。 | reuseAddress | boolean | 否 | 是否重用地址。默认为false。 | | socketTimeout | number | 否 | 套接字超时时间,单位毫秒(ms)。 | -## SocketStateBase +## SocketStateBase7+ Socket的状态信息。 @@ -704,7 +698,7 @@ Socket的状态信息。 | isClose | boolean | 是 | 是否关闭。 | | isConnected | boolean | 是 | 是否连接。 | -## SocketRemoteInfo +## SocketRemoteInfo7+ Socket的连接信息。 @@ -723,7 +717,7 @@ UDP 其余错误码映射形式为:2301000 + Linux内核错误码。 错误码的详细介绍参见[Socket错误码](../errorcodes/errorcode-net-socket.md) -## socket.constructTCPSocketInstance +## socket.constructTCPSocketInstance7+ constructTCPSocketInstance(): TCPSocket @@ -743,19 +737,16 @@ constructTCPSocketInstance(): TCPSocket let tcp = socket.constructTCPSocketInstance(); ``` -## TCPSocket +## TCPSocket7+ TCPSocket连接。在调用TCPSocket的方法前,需要先通过[socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance)创建TCPSocket对象。 -### bind +### bind7+ bind(address: NetAddress, callback: AsyncCallback\): void 绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方法作为异步方法。 -> **说明:** -> 客户端使用该方法创建socket。 - **需要权限**:ohos.permission.INTERNET **系统能力**:SystemCapability.Communication.NetStack @@ -778,7 +769,7 @@ bind(address: NetAddress, callback: AsyncCallback\): void ```js let tcp = socket.constructTCPSocketInstance(); -tcp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { +tcp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); return; @@ -787,15 +778,12 @@ tcp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { }) ``` -### bind +### bind7+ bind(address: NetAddress): Promise\ 绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。 -> **说明:** -> 客户端使用该方法创建socket。 - **需要权限**:ohos.permission.INTERNET **系统能力**:SystemCapability.Communication.NetStack @@ -831,7 +819,7 @@ promise.then(() => { }); ``` -### connect +### connect7+ connect(options: TCPConnectOptions, callback: AsyncCallback\): void @@ -871,7 +859,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim }) ``` -### connect +### connect7+ connect(options: TCPConnectOptions): Promise\ @@ -912,7 +900,7 @@ promise.then(() => { }); ``` -### send +### send7+ send(options: TCPSendOptions, callback: AsyncCallback\): void @@ -958,7 +946,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim }) ``` -### send +### send7+ send(options: TCPSendOptions): Promise\ @@ -1010,7 +998,7 @@ promise1.then(() => { }); ``` -### close +### close7+ close(callback: AsyncCallback\): void @@ -1045,7 +1033,7 @@ tcp.close(err => { }) ``` -### close +### close7+ close(): Promise\ @@ -1079,7 +1067,7 @@ promise.then(() => { }); ``` -### getRemoteAddress +### getRemoteAddress7+ getRemoteAddress(callback: AsyncCallback\): void @@ -1120,7 +1108,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim }); ``` -### getRemoteAddress +### getRemoteAddress7+ getRemoteAddress(): Promise\ @@ -1163,7 +1151,7 @@ promise1.then(() => { }); ``` -### getState +### getState7+ getState(callback: AsyncCallback\): void @@ -1204,7 +1192,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa }); ``` -### getState +### getState7+ getState(): Promise\ @@ -1247,7 +1235,7 @@ promise.then(() => { }); ``` -### setExtraOptions +### setExtraOptions7+ setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\): void @@ -1299,7 +1287,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa }); ``` -### setExtraOptions +### setExtraOptions7+ setExtraOptions(options: TCPExtraOptions): Promise\ @@ -1358,7 +1346,7 @@ promise.then(() => { }); ``` -### on('message') +### on('message')7+ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void @@ -1389,7 +1377,7 @@ tcp.on('message', value => { }); ``` -### off('message') +### off('message')7+ off(type: 'message', callback?: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void @@ -1427,7 +1415,7 @@ tcp.off('message', callback); tcp.off('message'); ``` -### on('connect' | 'close') +### on('connect' | 'close')7+ on(type: 'connect' | 'close', callback: Callback\): void @@ -1454,7 +1442,7 @@ tcp.on('close', () => { }); ``` -### off('connect' | 'close') +### off('connect' | 'close')7+ off(type: 'connect' | 'close', callback?: Callback\): void @@ -1492,7 +1480,7 @@ tcp.off('close', callback2); tcp.off('close'); ``` -### on('error') +### on('error')7+ on(type: 'error', callback: ErrorCallback): void @@ -1516,7 +1504,7 @@ tcp.on('error', err => { }); ``` -### off('error') +### off('error')7+ off(type: 'error', callback?: ErrorCallback): void @@ -1547,7 +1535,7 @@ tcp.off('error', callback); tcp.off('error'); ``` -## TCPConnectOptions +## TCPConnectOptions7+ TCPSocket连接的参数。 @@ -1558,7 +1546,7 @@ TCPSocket连接的参数。 | address | [NetAddress](#netaddress) | 是 | 绑定的地址以及端口。 | | timeout | number | 否 | 超时时间,单位毫秒(ms)。 | -## TCPSendOptions +## TCPSendOptions7+ TCPSocket发送请求的参数。 @@ -1569,7 +1557,7 @@ TCPSocket发送请求的参数。 | data | string\| ArrayBuffer7+ | 是 | 发送的数据。 | | encoding | string | 否 | 字符编码(UTF-8,UTF-16BE,UTF-16LE,UTF-16,US-AECII,ISO-8859-1),默认为UTF-8。 | -## TCPExtraOptions +## TCPExtraOptions7+ TCPSocket连接的其他属性。 @@ -1881,7 +1869,7 @@ promise.then(() => { }); ``` -### on('message') +### on('message')9+ on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void; @@ -1912,7 +1900,7 @@ tls.on('message', value => { }); ``` -### off('message') +### off('message')9+ off(type: 'message', callback?: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void @@ -1948,7 +1936,7 @@ tls.on('message', callback); // 可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。 tls.off('message', callback); ``` -### on('connect' | 'close') +### on('connect' | 'close')9+ on(type: 'connect' | 'close', callback: Callback\): void @@ -1975,7 +1963,7 @@ tls.on('close', () => { }); ``` -### off('connect' | 'close') +### off('connect' | 'close')9+ off(type: 'connect' | 'close', callback?: Callback\): void @@ -2012,7 +2000,7 @@ tls.on('close', callback2); tls.off('close', callback2); ``` -### on('error') +### on('error')9+ on(type: 'error', callback: ErrorCallback): void @@ -2036,7 +2024,7 @@ tls.on('error', err => { }); ``` -### off('error') +### off('error')9+ off(type: 'error', callback?: ErrorCallback): void @@ -2675,7 +2663,7 @@ send(data: string, callback: AsyncCallback\): void | ------- | -------------------------------------------- | | 401 | Parameter error. | | 2303501 | SSL is null. | -| 2303503 | Error in tls writing | +| 2303503 | Error in tls writing. | | 2303505 | Error occurred in the tls system call. | | 2303506 | Error clearing tls connection. | | 2300002 | System internal error. | @@ -2712,7 +2700,7 @@ send(data: string): Promise\ | ------- | -------------------------------------------- | | 401 | Parameter error. | | 2303501 | SSL is null. | -| 2303503 | Error in tls writing | +| 2303503 | Error in tls writing. | | 2303505 | Error occurred in the tls system call. | | 2303506 | Error clearing tls connection. | | 2300002 | System internal error. | @@ -2847,6 +2835,3 @@ TLS通信的协议版本。 **系统能力**:SystemCapability.Communication.NetStack -| 类型 | 说明 | -| --------------------------------------------------------------------- | --------------------- | -|[cert.EncodingBlob](js-apis-cert.md#datablob) | 存储证书的数据和编码格式 | diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-fetch.md b/zh-cn/application-dev/reference/apis/js-apis-system-fetch.md index b4e7eb8eccbab3614d8182eb6492a9a9ce189d48..02d164a071dc5ff4b4d5cda5cc4e07c0e37a1152 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-system-fetch.md +++ b/zh-cn/application-dev/reference/apis/js-apis-system-fetch.md @@ -16,7 +16,48 @@ import fetch from '@system.fetch'; ## fetch.fetch3+ -fetch(Object): void +fetch(options:{ + /** + * Resource URL. + * @since 3 + */ + url: string; + /** + * Request parameter, which can be of the string type or a JSON object. + * @since 3 + */ + data?: string | object; + /** + * Request header, which accommodates all attributes of the request. + * @since 3 + */ + header?: Object; + /** + * Request methods available: OPTIONS, GET, HEAD, POST, PUT, DELETE and TRACE. The default value is GET. + * @since 3 + */ + method?: string; + /** + * The return type can be text, or JSON. By default, the return type is determined based on Content-Type in the header returned by the server. + * @since 3 + */ + responseType?: string; + /** + * Called when the network data is obtained successfully. + * @since 3 + */ + success?: (data: FetchResponse) => void; + /** + * Called when the network data fails to be obtained. + * @since 3 + */ + fail?: (data: any, code: number) => void; + /** + * Called when the execution is completed. + * @since 3 + */ + complete?: () => void; + } ): void 通过网络获取数据。 @@ -43,7 +84,9 @@ fetch(Object): void | Object | 不设置 | Content-Type默认为application/x-www-form-urlencoded,data按照资源地址规则进行encode拼接作为请求的body。 | | Object | application/x-www-form-urlencoded | data按照资源地址规则进行encode拼接作为请求的body。 | -## FetchResponse +## FetchResponse3+ + +**系统能力:** SystemCapability.Communication.NetStack | 名称 | 类型 | 可读 | 可写 | 说明 | | -------- | -------- | -------- | -------- | -------- | diff --git a/zh-cn/application-dev/reference/apis/js-apis-system-network.md b/zh-cn/application-dev/reference/apis/js-apis-system-network.md index 85e7aa74af1e2d315ba9d602d61528d2a1a4caa6..c0fe499095370b61e34e069bbcbdca13bd77c4f6 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-system-network.md +++ b/zh-cn/application-dev/reference/apis/js-apis-system-network.md @@ -21,9 +21,25 @@ ohos.permission.GET_WIFI_INFO ohos.permission.GET_NETWORK_INFO -## network.getType - -getType(Object): void +## network.getType3+ + +getType(options?: { + /** + * Called when the network type is obtained. + * @since 3 + */ + success?: (data: NetworkResponse) => void; + /** + * Called when the network type fails to be obtained. + * @since 3 + */ + fail?: (data: any, code: number) => void; + /** + * Called when the execution is completed. + * @since 3 + */ + complete?: () => void; + }): void 获取当前设备的网络类型。 @@ -61,9 +77,20 @@ export default { ``` -## network.subscribe +## network.subscribe3+ -subscribe(Object): void +subscribe(options?:{ + /** + * Called when the network connection state changes. + * @since 3 + */ + success?: (data: NetworkResponse) => void; + /** + * Called when the listening fails. + * @since 3 + */ + fail?: (data: any, code: number) => void; + }): void 订阅当前设备的网络连接状态。如果多次调用,会覆盖前一次调用。 @@ -101,7 +128,7 @@ export default { ``` -## network.unsubscribe +## network.unsubscribe3+ unsubscribe(): void @@ -120,11 +147,11 @@ export default { ``` -## NetworkResponse +## NetworkResponse3+ **系统能力:** SystemCapability.Communication.NetManager.Core | 名称 | 类型 | 必填 | 说明 | | -------- | -------- | -------- | -------- | | metered | boolean | 否 |是否按照流量计费。 | -| type | string | 是|网络类型,可能的值有2g,3g,4g,5g,wifi,none等。 | \ No newline at end of file +| type | string | 是|网络类型,可能的值有2g,3g,4g,5g,wifi,none等。 | diff --git a/zh-cn/application-dev/reference/apis/js-apis-webSocket.md b/zh-cn/application-dev/reference/apis/js-apis-webSocket.md index a6474bf69108d1bb6e627fd086dabd26dec5ae04..4bd5f1d6647ea88379ef5f3872f70d0fbcfe9f72 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-webSocket.md +++ b/zh-cn/application-dev/reference/apis/js-apis-webSocket.md @@ -67,7 +67,7 @@ ws.connect(defaultIpAddress, (err, value) => { }); ``` -## webSocket.createWebSocket +## webSocket.createWebSocket6+ createWebSocket(): WebSocket @@ -87,11 +87,11 @@ createWebSocket(): WebSocket let ws = webSocket.createWebSocket(); ``` -## WebSocket +## WebSocket6+ 在调用WebSocket的方法前,需要先通过[webSocket.createWebSocket](#websocketcreatewebsocket)创建一个WebSocket。 -### connect +### connect6+ connect(url: string, callback: AsyncCallback\): void @@ -132,7 +132,7 @@ ws.connect(url, (err, value) => { }); ``` -### connect +### connect6+ connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback\): void @@ -179,7 +179,7 @@ ws.connect(url, { }); ``` -### connect +### connect6+ connect(url: string, options?: WebSocketRequestOptions): Promise\ @@ -225,7 +225,7 @@ promise.then((value) => { }); ``` -### send +### send6+ send(data: string | ArrayBuffer, callback: AsyncCallback\): void @@ -265,7 +265,7 @@ ws.connect(url, (err, value) => { }); ``` -### send +### send6+ send(data: string | ArrayBuffer): Promise\ @@ -309,7 +309,7 @@ ws.connect(url, (err, value) => { }); ``` -### close +### close6+ close(callback: AsyncCallback\): void @@ -345,7 +345,7 @@ ws.close((err, value) => { }); ``` -### close +### close6+ close(options: WebSocketCloseOptions, callback: AsyncCallback\): void @@ -385,7 +385,7 @@ ws.close({ }); ``` -### close +### close6+ close(options?: WebSocketCloseOptions): Promise\ @@ -429,7 +429,7 @@ promise.then((value) => { }); ``` -### on('open') +### on('open')6+ on(type: 'open', callback: AsyncCallback\): void @@ -453,7 +453,7 @@ ws.on('open', (err, value) => { }); ``` -### off('open') +### off('open')6+ off(type: 'open', callback?: AsyncCallback\): void @@ -483,7 +483,7 @@ ws.on('open', callback1); ws.off('open', callback1); ``` -### on('message') +### on('message')6+ on(type: 'message', callback: AsyncCallback\): void @@ -510,7 +510,7 @@ ws.on('message', (err, value) => { }); ``` -### off('message') +### off('message')6+ off(type: 'message', callback?: AsyncCallback\): void @@ -536,7 +536,7 @@ let ws = webSocket.createWebSocket(); ws.off('message'); ``` -### on('close') +### on('close')6+ on(type: 'close', callback: AsyncCallback\<{ code: number, reason: string }\>): void @@ -560,7 +560,7 @@ ws.on('close', (err, value) => { }); ``` -### off('close') +### off('close')6+ off(type: 'close', callback?: AsyncCallback\<{ code: number, reason: string }\>): void @@ -585,7 +585,7 @@ let ws = webSocket.createWebSocket(); ws.off('close'); ``` -### on('error') +### on('error')6+ on(type: 'error', callback: ErrorCallback): void @@ -609,7 +609,7 @@ ws.on('error', (err) => { }); ``` -### off('error') +### off('error')6+ off(type: 'error', callback?: ErrorCallback): void @@ -668,4 +668,3 @@ ws.off('error'); | 1002 | 协议错误 | | 1003 | 无法处理的数据类型 | | 1004~1015 | 保留值 | -