未验证 提交 cc454c67 编写于 作者: O openharmony_ci 提交者: Gitee

!17809 js-docs整改

Merge pull request !17809 from 徐杰/zy0429
......@@ -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.createHttp<sup>6+</sup>
createHttp(): HttpRequest
......@@ -94,7 +95,7 @@ let httpRequest = http.createHttp();
HTTP请求任务。在调用HttpRequest的方法前,需要先通过[createHttp()](#httpcreatehttp)创建一个任务。
### request
### request<sup>6+</sup>
request(url: string, callback: AsyncCallback\<HttpResponse\>):void
......@@ -120,10 +121,34 @@ request(url: string, callback: AsyncCallback\<HttpResponse\>):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
### request<sup>6+</sup>
request(url: string, options: HttpRequestOptions, callback: AsyncCallback\<HttpResponse\>):void
......@@ -231,7 +256,7 @@ httpRequest.request("EXAMPLE_URL",
});
```
### request
### request<sup>6+</sup>
request(url: string, options? : HttpRequestOptions): Promise\<HttpResponse\>
......@@ -357,10 +382,34 @@ request2(url: string, callback: AsyncCallback\<number\>): 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')<sup>10+</sup>
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
## HttpRequestOptions<sup>6+</sup>
发起请求可选参数的类型和取值范围。
......@@ -819,9 +868,10 @@ httpRequest.off('dataProgress');
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。<br />设置为0表示不会出现超时情况。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| usingProtocol<sup>9+</sup> | [HttpProtocol](#httpprotocol9) | 否 | 使用协议。默认值由系统自动指定。 |
| usingProxy<sup>10+</sup> | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。<br />- 当usingProxy为布尔类型true时,使用默认网络代理。<br />- 当usingProxy为object类型时,使用指定网络代理。 |
| usingProxy<sup>10+</sup> | boolean \| Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。<br />- 当usingProxy为布尔类型true时,使用默认网络代理。<br />- 当usingProxy为object类型时,使用指定网络代理。
| caPath<sup>10+</sup> | string | 否 | 如果设置了此参数,系统将使用用户指定路径的CA证书,否则将使用系统预设CA证书。 |
## RequestMethod
## RequestMethod<sup>6+</sup>
HTTP 请求方法。
......@@ -838,7 +888,7 @@ HTTP 请求方法。
| TRACE | "TRACE" | HTTP 请求 TRACE。 |
| CONNECT | "CONNECT" | HTTP 请求 CONNECT。 |
## ResponseCode
## ResponseCode<sup>6+</sup>
发起请求返回的响应码。
......@@ -882,7 +932,7 @@ HTTP 请求方法。
| GATEWAY_TIMEOUT | 504 | 充当网关或代理的服务器,未及时从远端服务器获取请求。 |
| VERSION | 505 | 服务器请求的HTTP协议的版本。 |
## HttpResponse
## HttpResponse<sup>6+</sup>
request方法回调函数的返回值类型。
......
......@@ -11,7 +11,7 @@
import connection from '@ohos.net.connection'
```
## connection.createNetConnection
## connection.createNetConnection<sup>8+</sup>
createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection
......@@ -46,7 +46,7 @@ let netConnectionCellular = connection.createNetConnection({
})
```
## connection.getDefaultNet
## connection.getDefaultNet<sup>8+</sup>
getDefaultNet(callback: AsyncCallback\<NetHandle>): void
......@@ -79,7 +79,7 @@ connection.getDefaultNet(function (error, data) {
})
```
## connection.getDefaultNet
## connection.getDefaultNet<sup>8+</sup>
getDefaultNet(): Promise\<NetHandle>
......@@ -444,7 +444,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getAllNets
## connection.getAllNets<sup>8+</sup>
getAllNets(callback: AsyncCallback&lt;Array&lt;NetHandle&gt;&gt;): void
......@@ -477,7 +477,7 @@ connection.getAllNets(function (error, data) {
});
```
## connection.getAllNets
## connection.getAllNets<sup>8+</sup>
getAllNets(): Promise&lt;Array&lt;NetHandle&gt;&gt;
......@@ -509,7 +509,7 @@ connection.getAllNets().then(function (data) {
});
```
## connection.getConnectionProperties
## connection.getConnectionProperties<sup>8+</sup>
getConnectionProperties(netHandle: NetHandle, callback: AsyncCallback\<ConnectionProperties>): void
......@@ -547,7 +547,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getConnectionProperties
## connection.getConnectionProperties<sup>8+</sup>
getConnectionProperties(netHandle: NetHandle): Promise\<ConnectionProperties>
......@@ -589,7 +589,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getNetCapabilities
## connection.getNetCapabilities<sup>8+</sup>
getNetCapabilities(netHandle: NetHandle, callback: AsyncCallback\<NetCapabilities>): void
......@@ -627,7 +627,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## connection.getNetCapabilities
## connection.getNetCapabilities<sup>8+</sup>
getNetCapabilities(netHandle: NetHandle): Promise\<NetCapabilities>
......@@ -734,7 +734,7 @@ connection.isDefaultNetMetered().then(function (data) {
})
```
## connection.hasDefaultNet
## connection.hasDefaultNet<sup>8+</sup>
hasDefaultNet(callback: AsyncCallback\<boolean>): void
......@@ -767,7 +767,7 @@ connection.hasDefaultNet(function (error, data) {
})
```
## connection.hasDefaultNet
## connection.hasDefaultNet<sup>8+</sup>
hasDefaultNet(): Promise\<boolean>
......@@ -799,7 +799,7 @@ connection.hasDefaultNet().then(function (data) {
})
```
## connection.enableAirplaneMode
## connection.enableAirplaneMode<sup>8+</sup>
enableAirplaneMode(callback: AsyncCallback\<void>): void
......@@ -821,6 +821,7 @@ enableAirplaneMode(callback: AsyncCallback\<void>): 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.enableAirplaneMode<sup>8+</sup>
enableAirplaneMode(): Promise\<void>
......@@ -854,6 +855,7 @@ enableAirplaneMode(): Promise\<void>
| 错误码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.disableAirplaneMode<sup>8+</sup>
disableAirplaneMode(callback: AsyncCallback\<void>): void
......@@ -887,6 +889,7 @@ disableAirplaneMode(callback: AsyncCallback\<void>): 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.disableAirplaneMode<sup>8+</sup>
disableAirplaneMode(): Promise\<void>
......@@ -920,6 +923,7 @@ disableAirplaneMode(): Promise\<void>
| 错误码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.reportNetConnected<sup>8+</sup>
reportNetConnected(netHandle: NetHandle, callback: AsyncCallback&lt;void&gt;): void
......@@ -968,7 +972,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetConnected
## connection.reportNetConnected<sup>8+</sup>
reportNetConnected(netHandle: NetHandle): Promise&lt;void&gt;
......@@ -1009,7 +1013,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetDisconnected
## connection.reportNetDisconnected<sup>8+</sup>
reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback&lt;void&gt;): void
......@@ -1046,7 +1050,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.reportNetDisconnected
## connection.reportNetDisconnected<sup>8+</sup>
reportNetDisconnected(netHandle: NetHandle): Promise&lt;void&gt;
......@@ -1087,7 +1091,7 @@ connection.getDefaultNet().then(function (netHandle) {
});
```
## connection.getAddressesByName
## connection.getAddressesByName<sup>8+</sup>
getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void
......@@ -1124,7 +1128,7 @@ connection.getAddressesByName(host, function (error, data) {
})
```
## connection.getAddressesByName
## connection.getAddressesByName<sup>8+</sup>
getAddressesByName(host: string): Promise\<Array\<NetAddress>>
......@@ -1174,7 +1178,7 @@ connection.getAddressesByName(host).then(function (data) {
> 设备从有网络到无网络状态会触发netLost事件;
> 设备从WiFi到蜂窝会触发netLost事件(WiFi丢失)之后触发 netAvaliable事件(蜂窝可用);
### register
### register<sup>8+</sup>
register(callback: AsyncCallback\<void>): void
......@@ -1195,9 +1199,10 @@ register(callback: AsyncCallback\<void>): 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
### unregister<sup>8+</sup>
unregister(callback: AsyncCallback\<void>): void
......@@ -1226,9 +1231,11 @@ unregister(callback: AsyncCallback\<void>): 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')<sup>8+</sup>
on(type: 'netAvailable', callback: Callback\<NetHandle>): void
......@@ -1277,7 +1284,7 @@ netCon.unregister(function (error) {
})
```
### on('netBlockStatusChange')
### on('netBlockStatusChange')<sup>8+</sup>
on(type: 'netBlockStatusChange', callback: Callback&lt;{ netHandle: NetHandle, blocked: boolean }&gt;): void
......@@ -1316,7 +1323,7 @@ netCon.unregister(function (error) {
})
```
### on('netCapabilitiesChange')
### on('netCapabilitiesChange')<sup>8+</sup>
on(type: 'netCapabilitiesChange', callback: Callback<{ netHandle: NetHandle, netCap: NetCapabilities }>): void
......@@ -1355,7 +1362,7 @@ netCon.unregister(function (error) {
})
```
### on('netConnectionPropertiesChange')
### on('netConnectionPropertiesChange')<sup>8+</sup>
on(type: 'netConnectionPropertiesChange', callback: Callback<{ netHandle: NetHandle, connectionProperties:
ConnectionProperties }>): void
......@@ -1395,7 +1402,7 @@ netCon.unregister(function (error) {
})
```
### on('netLost')
### on('netLost')<sup>8+</sup>
on(type: 'netLost', callback: Callback\<NetHandle>): void
......@@ -1434,7 +1441,7 @@ netCon.unregister(function (error) {
})
```
### on('netUnavailable')
### on('netUnavailable')<sup>8+</sup>
on(type: 'netUnavailable', callback: Callback\<void>): void
......@@ -1473,7 +1480,7 @@ netCon.unregister(function (error) {
})
```
## NetHandle
## NetHandle<sup>8+</sup>
数据网络的句柄。
......@@ -1640,7 +1647,7 @@ connection.getDefaultNet().then((netHandle) => {
})
```
### getAddressesByName
### getAddressesByName<sup>8+</sup>
getAddressesByName(host: string, callback: AsyncCallback\<Array\<NetAddress>>): void
......@@ -1679,7 +1686,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressesByName
### getAddressesByName<sup>8+</sup>
getAddressesByName(host: string): Promise\<Array\<NetAddress>>
......@@ -1722,7 +1729,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressByName
### getAddressByName<sup>8+</sup>
getAddressByName(host: string, callback: AsyncCallback\<NetAddress>): void
......@@ -1761,7 +1768,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
### getAddressByName
### getAddressByName<sup>8+</sup>
getAddressByName(host: string): Promise\<NetAddress>
......@@ -1804,7 +1811,7 @@ connection.getDefaultNet().then(function (netHandle) {
})
```
## NetCap
## NetCap<sup>8+</sup>
网络具体能力。
......@@ -1818,7 +1825,7 @@ connection.getDefaultNet().then(function (netHandle) {
| NET_CAPABILITY_NOT_VPN | 15 | 表示网络不使用VPN(Virtual&nbsp;Private&nbsp;Network,虚拟专用网络)。 |
| NET_CAPABILITY_VALIDATED | 16 | 表示该网络访问Internet的能力被网络管理成功验证,该能力由网络管理模块设置。 |
## NetBearType
## NetBearType<sup>8+</sup>
网络类型。
......@@ -1842,7 +1849,7 @@ connection.getDefaultNet().then(function (netHandle) {
| port | number | 否 | 主机端口。 |
| exclusionList | Array<string> | 否 | 不使用代理服务器的屏蔽列表,列表内元素拼接后长度不可超过96字节。<br>例如:“baidu.com,zhihu.com”为20字节。 |
## NetSpecifier
## NetSpecifier<sup>8+</sup>
提供承载数据网络能力的实例。
......@@ -1853,7 +1860,7 @@ connection.getDefaultNet().then(function (netHandle) {
| netCapabilities | [NetCapabilities](#netcapabilities) | 是 | 存储数据网络的传输能力和承载类型。 |
| bearerPrivateIdentifier | string | 否 | 网络标识符,Wi-Fi网络的标识符是"wifi",蜂窝网络的标识符是"slot0"(对应SIM卡1)。 |
## NetCapabilities
## NetCapabilities<sup>8+</sup>
网络的能力集。
......@@ -1866,7 +1873,7 @@ connection.getDefaultNet().then(function (netHandle) {
| networkCap | Array\<[NetCap](#netcap)> | 否 | 网络具体能力。 |
| bearerTypes | Array\<[NetBearType](#netbeartype)> | 是 | 网络类型。 |
## ConnectionProperties
## ConnectionProperties<sup>8+</sup>
网络连接信息。
......@@ -1881,7 +1888,7 @@ connection.getDefaultNet().then(function (netHandle) {
| dnses | Array\<[NetAddress](#netaddress)> | 是 |网络地址,参考[NetAddress](#netaddress)。 |
| mtu | number | 是 |最大传输单元。 |
## RouteInfo
## RouteInfo<sup>8+</sup>
网络路由信息。
......@@ -1895,7 +1902,7 @@ connection.getDefaultNet().then(function (netHandle) {
| hasGateway | boolean | 是 |是否有网关。 |
| isDefaultRoute | boolean | 是 |是否为默认路由。 |
## LinkAddress
## LinkAddress<sup>8+</sup>
网络链路信息。
......@@ -1906,7 +1913,7 @@ connection.getDefaultNet().then(function (netHandle) {
| address | [NetAddress](#netaddress) | 是 | 链路地址。 |
| prefixLength | number | 是 |链路地址前缀的长度。 |
## NetAddress
## NetAddress<sup>8+</sup>
网络地址。
......
......@@ -11,7 +11,7 @@
import ethernet from '@ohos.net.ethernet'
```
## ethernet.setIfaceConfig
## ethernet.setIfaceConfig<sup>9+</sup>
setIfaceConfig(iface: string, ic: InterfaceConfiguration, callback: AsyncCallback\<void>): 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.setIfaceConfig<sup>9+</sup>
setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<void>
......@@ -94,13 +96,15 @@ setIfaceConfig(iface: string, ic: InterfaceConfiguration): Promise\<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. |
| 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.getIfaceConfig<sup>9+</sup>
getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>): void
......@@ -144,11 +148,12 @@ getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>):
| 错误码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.getIfaceConfig<sup>9+</sup>
getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
......@@ -197,11 +202,12 @@ getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
| 错误码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.isIfaceActive<sup>9+</sup>
isIfaceActive(iface: string, callback: AsyncCallback\<number>): void
......@@ -243,11 +249,12 @@ isIfaceActive(iface: string, callback: AsyncCallback\<number>): 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.isIfaceActive<sup>9+</sup>
isIfaceActive(iface: string): Promise\<number>
......@@ -290,11 +297,12 @@ isIfaceActive(iface: string): Promise\<number>
| 错误码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.getAllActiveIfaces<sup>9+</sup>
getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void
......@@ -329,6 +337,7 @@ getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): 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.getAllActiveIfaces<sup>9+</sup>
getAllActiveIfaces(): Promise\<Array\<string>>
......@@ -370,6 +379,7 @@ getAllActiveIfaces(): Promise\<Array\<string>>
| 错误码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 }\> | 是 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) |
| callback | AsyncCallback\<{ iface: string, active: boolean }\> | 是 | 回调函数。<br>iface:网卡名称。<br>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 }> | 否 | 回调函数。<br>iface:网卡名称。<br>active:是否处于激活状态(true:激活;false:未激活) |
| callback | AsyncCallback\<{ iface: string, active: boolean }> | 否 | 回调函数。<br>iface:网卡名称。<br>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
## InterfaceConfiguration<sup>9+</sup>
以太网连接配置网络信息。
......@@ -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
## IPSetMode<sup>9+</sup>
以太网连接模式。
......
......@@ -11,7 +11,7 @@ MDNS即多播DNS(Multicast DNS),提供局域网内的本地服务添加、
import mdns from '@ohos.net.mdns'
```
## mdns.addLocalService
## mdns.addLocalService<sup>10+</sup>
addLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\<LocalServiceInfo>): void
......@@ -100,7 +100,7 @@ mdns.addLocalService(context, localServiceInfo, function (error, data) {
});
```
## mdns.addLocalService
## mdns.addLocalService<sup>10+</sup>
addLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\<LocalServiceInfo>
......@@ -192,7 +192,7 @@ mdns.addLocalService(context, localServiceInfo).then(function (data) {
});
```
## mdns.removeLocalService
## mdns.removeLocalService<sup>10+</sup>
removeLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\<LocalServiceInfo>): 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.removeLocalService<sup>10+</sup>
removeLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\<LocalServiceInfo>
......@@ -310,7 +310,7 @@ removeLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\<Lo
| 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. |
> **错误码说明:**
......@@ -373,7 +373,7 @@ mdns.removeLocalService(context, localServiceInfo).then(function (data) {
});
```
## mdns.createDiscoveryService
## mdns.createDiscoveryService<sup>10+</sup>
createDiscoveryService(context: Context, serviceType: string): DiscoveryService
......@@ -423,7 +423,7 @@ let serviceType = "_print._tcp";
let discoveryService = mdns.createDiscoveryService(context, serviceType);
```
## mdns.resolveLocalService
## mdns.resolveLocalService<sup>10+</sup>
resolveLocalService(context: Context, serviceInfo: LocalServiceInfo, callback: AsyncCallback\<LocalServiceInfo>): void
......@@ -512,7 +512,7 @@ mdns.resolveLocalService(context, localServiceInfo, function (error, data) {
});
```
## mdns.resolveLocalService
## mdns.resolveLocalService<sup>10+</sup>
resolveLocalService(context: Context, serviceInfo: LocalServiceInfo): Promise\<LocalServiceInfo>
......@@ -603,11 +603,11 @@ mdns.resolveLocalService(context, localServiceInfo).then(function (data) {
console.log(JSON.stringify(data));
});
```
## DiscoveryService
## DiscoveryService<sup>10+</sup>
指定服务类型的发现服务对象。
### startSearchingMDNS
### startSearchingMDNS<sup>10+</sup>
startSearchingMDNS(): void
......@@ -644,7 +644,7 @@ let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.startSearchingMDNS();
```
### stopSearchingMDNS
### stopSearchingMDNS<sup>10+</sup>
stopSearchingMDNS(): void
......@@ -681,7 +681,7 @@ let discoveryService = mdns.createDiscoveryService(context, serviceType);
discoveryService.stopSearchingMDNS();
```
### on('discoveryStart')
### on('discoveryStart')<sup>10+</sup>
on(type: 'discoveryStart', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void
......@@ -710,7 +710,7 @@ discoveryService.on('discoveryStart', (data) => {
discoveryService.stopSearchingMDNS();
```
### on('discoveryStop')
### on('discoveryStop')<sup>10+</sup>
on(type: 'discoveryStop', callback: Callback<{serviceInfo: LocalServiceInfo, errorCode?: MdnsError}>): void
......@@ -739,7 +739,7 @@ discoveryService.on('discoveryStop', (data) => {
discoveryService.stopSearchingMDNS();
```
### on('serviceFound')
### on('serviceFound')<sup>10+</sup>
on(type: 'serviceFound', callback: Callback\<LocalServiceInfo>): void
......@@ -768,7 +768,7 @@ discoveryService.on('serviceFound', (data) => {
discoveryService.stopSearchingMDNS();
```
### on('serviceLost')
### on('serviceLost')<sup>10+</sup>
on(type: 'serviceLost', callback: Callback\<LocalServiceInfo>): void
......@@ -797,7 +797,7 @@ discoveryService.on('serviceLost', (data) => {
discoveryService.stopSearchingMDNS();
```
## LocalServiceInfo
## LocalServiceInfo<sup>10+</sup>
mDNS服务信息
......@@ -811,7 +811,7 @@ mDNS服务信息
| host | [NetAddress](js-apis-net-connection.md#netaddress) | 否 | mDNS服务设备的IP地址。采用设备的IP,添加服务和移除服务时候不生效。 |
| serviceAttribute | serviceAttribute\<[ServiceAttribute](#serviceattribute)> | 否 | mDNS服务属性信息。 |
## ServiceAttribute
## ServiceAttribute<sup>10+</sup>
mDNS服务属性信息
......
......@@ -12,7 +12,7 @@
import sharing from '@ohos.net.sharing'
```
## sharing.isSharingSupported
## sharing.isSharingSupported<sup>9+</sup>
isSharingSupported(callback: AsyncCallback\<boolean>): void
......@@ -48,7 +48,7 @@ sharing.isSharingSupported((error, data) => {
});
```
## sharing.isSharingSupported
## sharing.isSharingSupported<sup>9+</sup>
isSharingSupported(): Promise\<boolean>
......@@ -85,7 +85,7 @@ sharing.isSharingSupported().then(data => {
});
```
## sharing.isSharing
## sharing.isSharing<sup>9+</sup>
isSharing(callback: AsyncCallback\<boolean>): void
......@@ -108,8 +108,10 @@ isSharing(callback: AsyncCallback\<boolean>): 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.isSharing<sup>9+</sup>
isSharing(): Promise\<boolean>
......@@ -143,8 +145,10 @@ isSharing(): Promise\<boolean>
| 错误码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.startSharing<sup>9+</sup>
startSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
......@@ -201,7 +205,7 @@ sharing.startSharing(SHARING_WIFI, (error) => {
});
```
## sharing.startSharing
## sharing.startSharing<sup>9+</sup>
startSharing(type: SharingIfaceType): Promise\<void>
......@@ -253,7 +257,7 @@ sharing.startSharing(SHARING_WIFI).then(() => {
});
```
## sharing.stopSharing
## sharing.stopSharing<sup>9+</sup>
stopSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): void
......@@ -277,10 +281,12 @@ stopSharing(type: SharingIfaceType, callback: AsyncCallback\<void>): 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.stopSharing<sup>9+</sup>
stopSharing(type: SharingIfaceType): Promise\<void>
......@@ -325,10 +331,12 @@ stopSharing(type: SharingIfaceType): Promise\<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. |
......@@ -346,7 +354,7 @@ sharing.stopSharing(SHARING_WIFI).then(() => {
});
```
## sharing.getStatsRxBytes
## sharing.getStatsRxBytes<sup>9+</sup>
getStatsRxBytes(callback: AsyncCallback\<number>): void
......@@ -381,7 +389,7 @@ sharing.getStatsRxBytes((error, data) => {
});
```
## sharing.getStatsRxBytes
## sharing.getStatsRxBytes<sup>9+</sup>
getStatsRxBytes(): Promise\<number>
......@@ -417,7 +425,7 @@ sharing.getStatsRxBytes().then(data => {
});
```
## sharing.getStatsTxBytes
## sharing.getStatsTxBytes<sup>9+</sup>
getStatsTxBytes(callback: AsyncCallback\<number>): void
......@@ -452,7 +460,7 @@ sharing.getStatsTxBytes((error, data) => {
});
```
## sharing.getStatsTxBytes
## sharing.getStatsTxBytes<sup>9+</sup>
getStatsTxBytes(): Promise\<number>
......@@ -488,7 +496,7 @@ sharing.getStatsTxBytes().then(data => {
});
```
## sharing.getStatsTotalBytes
## sharing.getStatsTotalBytes<sup>9+</sup>
getStatsTotalBytes(callback: AsyncCallback\<number>): void
......@@ -523,7 +531,7 @@ sharing.getStatsTotalBytes((error, data) => {
});
```
## sharing.getStatsTotalBytes
## sharing.getStatsTotalBytes<sup>9+</sup>
getStatsTotalBytes(): Promise\<number>
......@@ -559,7 +567,7 @@ sharing.getStatsTotalBytes().then(data => {
});
```
## sharing.getSharingIfaces
## sharing.getSharingIfaces<sup>9+</sup>
getSharingIfaces(state: SharingIfaceState, callback: AsyncCallback\<Array\<string>>): void
......@@ -600,7 +608,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH, (error, data) => {
});
```
## sharing.getSharingIfaces
## sharing.getSharingIfaces<sup>9+</sup>
getSharingIfaces(state: SharingIfaceState): Promise\<Array\<string>>
......@@ -647,7 +655,7 @@ sharing.getSharingIfaces(SHARING_BLUETOOTH).then(data => {
});
```
## sharing.getSharingState
## sharing.getSharingState<sup>9+</sup>
getSharingState(type: SharingIfaceType, callback: AsyncCallback\<SharingIfaceState>): void
......@@ -688,7 +696,7 @@ sharing.getSharingState(SHARING_WIFI, (error, data) => {
});
```
## sharing.getSharingState
## sharing.getSharingState<sup>9+</sup>
getSharingState(type: SharingIfaceType): Promise\<SharingIfaceState>
......@@ -735,7 +743,7 @@ sharing.getSharingState(SHARING_WIFI).then(data => {
});
```
## sharing.getSharableRegexes
## sharing.getSharableRegexes<sup>9+</sup>
getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\<Array\<string>>): void
......@@ -776,7 +784,7 @@ sharing.getSharableRegexes(SHARING_WIFI, (error, data) => {
});
```
## sharing.getSharableRegexes
## sharing.getSharableRegexes<sup>9+</sup>
getSharableRegexes(type: SharingIfaceType): Promise\<Array\<string>>
......@@ -823,7 +831,7 @@ sharing.getSharableRegexes(SHARING_WIFI).then(data => {
});
```
## sharing.on('sharingStateChange')
## sharing.on('sharingStateChange')<sup>9+</sup>
on(type: 'sharingStateChange', callback: Callback\<boolean>): void
......@@ -846,8 +854,7 @@ on(type: 'sharingStateChange', callback: Callback\<boolean>): 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')<sup>9+</sup>
off(type: 'sharingStateChange', callback?: Callback\<boolean>): void
......@@ -880,8 +887,7 @@ off(type: 'sharingStateChange', callback?: Callback\<boolean>): 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')<sup>9+</sup>
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')<sup>9+</sup>
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')<sup>9+</sup>
on(type: 'sharingUpstreamChange', callback: Callback\<NetHandle>): void
......@@ -984,8 +988,7 @@ on(type: 'sharingUpstreamChange', callback: Callback\<NetHandle>): 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')<sup>9+</sup>
off(type: 'sharingUpstreamChange', callback?: Callback\<NetHandle>): void
......@@ -1018,8 +1021,7 @@ off(type: 'sharingUpstreamChange', callback?: Callback\<NetHandle>): void
| 错误码ID | 错误信息 |
| ------- | -------------------------------------------- |
| 201 | Permission denied. |
| 401 | Parameter error. |
| 202 | Non-system applications use system APIs. |
**示例:**
......@@ -1029,7 +1031,7 @@ sharing.off('sharingUpstreamChange', (data) => {
});
```
## SharingIfaceState
## SharingIfaceState<sup>9+</sup>
网络共享状态。
......@@ -1043,7 +1045,7 @@ sharing.off('sharingUpstreamChange', (data) => {
| SHARING_NIC_CAN_SERVER | 2 | 可提供网络共享。 |
| SHARING_NIC_ERROR | 3 | 网络共享错误。 |
## SharingIfaceType
## SharingIfaceType<sup>9+</sup>
网络共享类型。
......
......@@ -12,7 +12,7 @@
import socket from '@ohos.net.socket';
```
## socket.constructUDPSocketInstance
## socket.constructUDPSocketInstance<sup>7+</sup>
constructUDPSocketInstance(): UDPSocket
......@@ -32,19 +32,16 @@ constructUDPSocketInstance(): UDPSocket
let udp = socket.constructUDPSocketInstance();
```
## UDPSocket
## UDPSocket<sup>7+</sup>
UDPSocket连接。在调用UDPSocket的方法前,需要先通过[socket.constructUDPSocketInstance](#socketconstructudpsocketinstance)创建UDPSocket对象。
### bind
### bind<sup>7+</sup>
bind(address: NetAddress, callback: AsyncCallback\<void\>): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
......@@ -67,7 +64,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): 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
### bind<sup>7+</sup>
bind(address: NetAddress): Promise\<void\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方式作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
......@@ -120,7 +114,7 @@ promise.then(() => {
});
```
### send
### send<sup>7+</sup>
send(options: UDPSendOptions, callback: AsyncCallback\<void\>): void
......@@ -166,7 +160,7 @@ udp.send({
})
```
### send
### send<sup>7+</sup>
send(options: UDPSendOptions): Promise\<void\>
......@@ -216,7 +210,7 @@ promise.then(() => {
});
```
### close
### close<sup>7+</sup>
close(callback: AsyncCallback\<void\>): void
......@@ -245,7 +239,7 @@ udp.close(err => {
})
```
### close
### close<sup>7+</sup>
close(): Promise\<void\>
......@@ -273,7 +267,7 @@ promise.then(() => {
});
```
### getState
### getState<sup>7+</sup>
getState(callback: AsyncCallback\<SocketStateBase\>): void
......@@ -318,7 +312,7 @@ udp.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => {
})
```
### getState
### getState<sup>7+</sup>
getState(): Promise\<SocketStateBase\>
......@@ -357,7 +351,7 @@ promise.then(err => {
});
```
### setExtraOptions
### setExtraOptions<sup>7+</sup>
setExtraOptions(options: UDPExtraOptions, callback: AsyncCallback\<void\>): void
......@@ -410,7 +404,7 @@ udp.bind({ address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => {
})
```
### setExtraOptions
### setExtraOptions<sup>7+</sup>
setExtraOptions(options: UDPExtraOptions): Promise\<void\>
......@@ -466,7 +460,7 @@ promise.then(() => {
});
```
### on('message')
### on('message')<sup>7+</sup>
on(type: 'message', callback: Callback\<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
......@@ -497,7 +491,7 @@ udp.on('message', value => {
});
```
### off('message')
### off('message')<sup>7+</sup>
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')<sup>7+</sup>
on(type: 'listening' | 'close', callback: Callback\<void\>): void
......@@ -562,7 +556,7 @@ udp.on('close', () => {
});
```
### off('listening' | 'close')
### off('listening' | 'close')<sup>7+</sup>
off(type: 'listening' | 'close', callback?: Callback\<void\>): void
......@@ -600,7 +594,7 @@ udp.off('close', callback2);
udp.off('close');
```
### on('error')
### on('error')<sup>7+</sup>
on(type: 'error', callback: ErrorCallback): void
......@@ -624,7 +618,7 @@ udp.on('error', err => {
});
```
### off('error')
### off('error')<sup>7+</sup>
off(type: 'error', callback?: ErrorCallback): void
......@@ -655,7 +649,7 @@ udp.off('error', callback);
udp.off('error');
```
## NetAddress
## NetAddress<sup>7+</sup>
目标地址信息。
......@@ -667,7 +661,7 @@ udp.off('error');
| port | number | 否 | 端口号 ,范围0~65535。如果不指定系统随机分配端口。 |
| family | number | 否 | 网络协议类型,可选类型:<br />- 1:IPv4<br />- 2:IPv6<br />默认为1。 |
## UDPSendOptions
## UDPSendOptions<sup>7+</sup>
UDPSocket发送参数。
......@@ -678,7 +672,7 @@ UDPSocket发送参数。
| data | string \| ArrayBuffer<sup>7+</sup> | 是 | 发送的数据。 |
| address | [NetAddress](#netaddress) | 是 | 目标地址信息。 |
## UDPExtraOptions
## UDPExtraOptions<sup>7+</sup>
UDPSocket连接的其他属性。
......@@ -692,7 +686,7 @@ UDPSocket连接的其他属性。
| reuseAddress | boolean | 否 | 是否重用地址。默认为false。 |
| socketTimeout | number | 否 | 套接字超时时间,单位毫秒(ms)。 |
## SocketStateBase
## SocketStateBase<sup>7+</sup>
Socket的状态信息。
......@@ -704,7 +698,7 @@ Socket的状态信息。
| isClose | boolean | 是 | 是否关闭。 |
| isConnected | boolean | 是 | 是否连接。 |
## SocketRemoteInfo
## SocketRemoteInfo<sup>7+</sup>
Socket的连接信息。
......@@ -723,7 +717,7 @@ UDP 其余错误码映射形式为:2301000 + Linux内核错误码。
错误码的详细介绍参见[Socket错误码](../errorcodes/errorcode-net-socket.md)
## socket.constructTCPSocketInstance
## socket.constructTCPSocketInstance<sup>7+</sup>
constructTCPSocketInstance(): TCPSocket
......@@ -743,19 +737,16 @@ constructTCPSocketInstance(): TCPSocket
let tcp = socket.constructTCPSocketInstance();
```
## TCPSocket
## TCPSocket<sup>7+</sup>
TCPSocket连接。在调用TCPSocket的方法前,需要先通过[socket.constructTCPSocketInstance](#socketconstructtcpsocketinstance)创建TCPSocket对象。
### bind
### bind<sup>7+</sup>
bind(address: NetAddress, callback: AsyncCallback\<void\>): void
绑定IP地址和端口,端口可以指定或由系统随机分配。使用callback方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
......@@ -778,7 +769,7 @@ bind(address: NetAddress, callback: AsyncCallback\<void\>): 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
### bind<sup>7+</sup>
bind(address: NetAddress): Promise\<void\>
绑定IP地址和端口,端口可以指定或由系统随机分配。使用Promise方法作为异步方法。
> **说明:**
> 客户端使用该方法创建socket。
**需要权限**:ohos.permission.INTERNET
**系统能力**:SystemCapability.Communication.NetStack
......@@ -831,7 +819,7 @@ promise.then(() => {
});
```
### connect
### connect<sup>7+</sup>
connect(options: TCPConnectOptions, callback: AsyncCallback\<void\>): void
......@@ -871,7 +859,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
})
```
### connect
### connect<sup>7+</sup>
connect(options: TCPConnectOptions): Promise\<void\>
......@@ -912,7 +900,7 @@ promise.then(() => {
});
```
### send
### send<sup>7+</sup>
send(options: TCPSendOptions, callback: AsyncCallback\<void\>): void
......@@ -958,7 +946,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
})
```
### send
### send<sup>7+</sup>
send(options: TCPSendOptions): Promise\<void\>
......@@ -1010,7 +998,7 @@ promise1.then(() => {
});
```
### close
### close<sup>7+</sup>
close(callback: AsyncCallback\<void\>): void
......@@ -1045,7 +1033,7 @@ tcp.close(err => {
})
```
### close
### close<sup>7+</sup>
close(): Promise\<void\>
......@@ -1079,7 +1067,7 @@ promise.then(() => {
});
```
### getRemoteAddress
### getRemoteAddress<sup>7+</sup>
getRemoteAddress(callback: AsyncCallback\<NetAddress\>): void
......@@ -1120,7 +1108,7 @@ tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, family: 1 }, tim
});
```
### getRemoteAddress
### getRemoteAddress<sup>7+</sup>
getRemoteAddress(): Promise\<NetAddress\>
......@@ -1163,7 +1151,7 @@ promise1.then(() => {
});
```
### getState
### getState<sup>7+</sup>
getState(callback: AsyncCallback\<SocketStateBase\>): void
......@@ -1204,7 +1192,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
});
```
### getState
### getState<sup>7+</sup>
getState(): Promise\<SocketStateBase\>
......@@ -1247,7 +1235,7 @@ promise.then(() => {
});
```
### setExtraOptions
### setExtraOptions<sup>7+</sup>
setExtraOptions(options: TCPExtraOptions, callback: AsyncCallback\<void\>): void
......@@ -1299,7 +1287,7 @@ let promise = tcp.connect({ address: { address: '192.168.xx.xxx', port: xxxx, fa
});
```
### setExtraOptions
### setExtraOptions<sup>7+</sup>
setExtraOptions(options: TCPExtraOptions): Promise\<void\>
......@@ -1358,7 +1346,7 @@ promise.then(() => {
});
```
### on('message')
### on('message')<sup>7+</sup>
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}\>): void
......@@ -1389,7 +1377,7 @@ tcp.on('message', value => {
});
```
### off('message')
### off('message')<sup>7+</sup>
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')<sup>7+</sup>
on(type: 'connect' | 'close', callback: Callback\<void\>): void
......@@ -1454,7 +1442,7 @@ tcp.on('close', () => {
});
```
### off('connect' | 'close')
### off('connect' | 'close')<sup>7+</sup>
off(type: 'connect' | 'close', callback?: Callback\<void\>): void
......@@ -1492,7 +1480,7 @@ tcp.off('close', callback2);
tcp.off('close');
```
### on('error')
### on('error')<sup>7+</sup>
on(type: 'error', callback: ErrorCallback): void
......@@ -1516,7 +1504,7 @@ tcp.on('error', err => {
});
```
### off('error')
### off('error')<sup>7+</sup>
off(type: 'error', callback?: ErrorCallback): void
......@@ -1547,7 +1535,7 @@ tcp.off('error', callback);
tcp.off('error');
```
## TCPConnectOptions
## TCPConnectOptions<sup>7+</sup>
TCPSocket连接的参数。
......@@ -1558,7 +1546,7 @@ TCPSocket连接的参数。
| address | [NetAddress](#netaddress) | 是 | 绑定的地址以及端口。 |
| timeout | number | 否 | 超时时间,单位毫秒(ms)。 |
## TCPSendOptions
## TCPSendOptions<sup>7+</sup>
TCPSocket发送请求的参数。
......@@ -1569,7 +1557,7 @@ TCPSocket发送请求的参数。
| data | string\| ArrayBuffer<sup>7+</sup> | 是 | 发送的数据。 |
| encoding | string | 否 | 字符编码(UTF-8,UTF-16BE,UTF-16LE,UTF-16,US-AECII,ISO-8859-1),默认为UTF-8。 |
## TCPExtraOptions
## TCPExtraOptions<sup>7+</sup>
TCPSocket连接的其他属性。
......@@ -1881,7 +1869,7 @@ promise.then(() => {
});
```
### on('message')
### on('message')<sup>9+</sup>
on(type: 'message', callback: Callback<{message: ArrayBuffer, remoteInfo: SocketRemoteInfo}>): void;
......@@ -1912,7 +1900,7 @@ tls.on('message', value => {
});
```
### off('message')
### off('message')<sup>9+</sup>
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')<sup>9+</sup>
on(type: 'connect' | 'close', callback: Callback\<void\>): void
......@@ -1975,7 +1963,7 @@ tls.on('close', () => {
});
```
### off('connect' | 'close')
### off('connect' | 'close')<sup>9+</sup>
off(type: 'connect' | 'close', callback?: Callback\<void\>): void
......@@ -2012,7 +2000,7 @@ tls.on('close', callback2);
tls.off('close', callback2);
```
### on('error')
### on('error')<sup>9+</sup>
on(type: 'error', callback: ErrorCallback): void
......@@ -2036,7 +2024,7 @@ tls.on('error', err => {
});
```
### off('error')
### off('error')<sup>9+</sup>
off(type: 'error', callback?: ErrorCallback): void
......@@ -2675,7 +2663,7 @@ send(data: string, callback: AsyncCallback\<void\>): 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\<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. |
......@@ -2847,6 +2835,3 @@ TLS通信的协议版本。
**系统能力**:SystemCapability.Communication.NetStack
| 类型 | 说明 |
| --------------------------------------------------------------------- | --------------------- |
|[cert.EncodingBlob](js-apis-cert.md#datablob) | 存储证书的数据和编码格式 |
......@@ -16,7 +16,48 @@ import fetch from '@system.fetch';
## fetch.fetch<sup>3+</sup>
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
## FetchResponse<sup>3+</sup>
**系统能力:** SystemCapability.Communication.NetStack
| 名称 | 类型 | 可读 | 可写 | 说明 |
| -------- | -------- | -------- | -------- | -------- |
......
......@@ -21,9 +21,25 @@ ohos.permission.GET_WIFI_INFO
ohos.permission.GET_NETWORK_INFO
## network.getType
getType(Object): void
## network.getType<sup>3+</sup>
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.subscribe<sup>3+</sup>
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.unsubscribe<sup>3+</sup>
unsubscribe(): void
......@@ -120,7 +147,7 @@ export default {
```
## NetworkResponse
## NetworkResponse<sup>3+</sup>
**系统能力:** SystemCapability.Communication.NetManager.Core
......
......@@ -67,7 +67,7 @@ ws.connect(defaultIpAddress, (err, value) => {
});
```
## webSocket.createWebSocket
## webSocket.createWebSocket<sup>6+</sup>
createWebSocket(): WebSocket
......@@ -87,11 +87,11 @@ createWebSocket(): WebSocket
let ws = webSocket.createWebSocket();
```
## WebSocket
## WebSocket<sup>6+</sup>
在调用WebSocket的方法前,需要先通过[webSocket.createWebSocket](#websocketcreatewebsocket)创建一个WebSocket。
### connect
### connect<sup>6+</sup>
connect(url: string, callback: AsyncCallback\<boolean\>): void
......@@ -132,7 +132,7 @@ ws.connect(url, (err, value) => {
});
```
### connect
### connect<sup>6+</sup>
connect(url: string, options: WebSocketRequestOptions, callback: AsyncCallback\<boolean\>): void
......@@ -179,7 +179,7 @@ ws.connect(url, {
});
```
### connect
### connect<sup>6+</sup>
connect(url: string, options?: WebSocketRequestOptions): Promise\<boolean\>
......@@ -225,7 +225,7 @@ promise.then((value) => {
});
```
### send
### send<sup>6+</sup>
send(data: string | ArrayBuffer, callback: AsyncCallback\<boolean\>): void
......@@ -265,7 +265,7 @@ ws.connect(url, (err, value) => {
});
```
### send
### send<sup>6+</sup>
send(data: string | ArrayBuffer): Promise\<boolean\>
......@@ -309,7 +309,7 @@ ws.connect(url, (err, value) => {
});
```
### close
### close<sup>6+</sup>
close(callback: AsyncCallback\<boolean\>): void
......@@ -345,7 +345,7 @@ ws.close((err, value) => {
});
```
### close
### close<sup>6+</sup>
close(options: WebSocketCloseOptions, callback: AsyncCallback\<boolean\>): void
......@@ -385,7 +385,7 @@ ws.close({
});
```
### close
### close<sup>6+</sup>
close(options?: WebSocketCloseOptions): Promise\<boolean\>
......@@ -429,7 +429,7 @@ promise.then((value) => {
});
```
### on('open')
### on('open')<sup>6+</sup>
on(type: 'open', callback: AsyncCallback\<Object\>): void
......@@ -453,7 +453,7 @@ ws.on('open', (err, value) => {
});
```
### off('open')
### off('open')<sup>6+</sup>
off(type: 'open', callback?: AsyncCallback\<Object\>): void
......@@ -483,7 +483,7 @@ ws.on('open', callback1);
ws.off('open', callback1);
```
### on('message')
### on('message')<sup>6+</sup>
on(type: 'message', callback: AsyncCallback\<string | ArrayBuffer\>): void
......@@ -510,7 +510,7 @@ ws.on('message', (err, value) => {
});
```
### off('message')
### off('message')<sup>6+</sup>
off(type: 'message', callback?: AsyncCallback\<string | ArrayBuffer\>): void
......@@ -536,7 +536,7 @@ let ws = webSocket.createWebSocket();
ws.off('message');
```
### on('close')
### on('close')<sup>6+</sup>
on(type: 'close', callback: AsyncCallback\<{ code: number, reason: string }\>): void
......@@ -560,7 +560,7 @@ ws.on('close', (err, value) => {
});
```
### off('close')
### off('close')<sup>6+</sup>
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')<sup>6+</sup>
on(type: 'error', callback: ErrorCallback): void
......@@ -609,7 +609,7 @@ ws.on('error', (err) => {
});
```
### off('error')
### off('error')<sup>6+</sup>
off(type: 'error', callback?: ErrorCallback): void
......@@ -668,4 +668,3 @@ ws.off('error');
| 1002 | 协议错误 |
| 1003 | 无法处理的数据类型 |
| 1004~1015 | 保留值 |
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册