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 05b1918f77632ca5f9c18d2c2efb3d6f66a3dc0a..563969d2e2dddf968412d7adf89ff829633950d5 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-http.md +++ b/zh-cn/application-dev/reference/apis/js-apis-http.md @@ -490,8 +490,6 @@ flush(callback: AsyncCallback\): void **示例:** ```js -import http from '@ohos.net.http'; -let httpResponseCache = http.createHttpResponseCache(); httpResponseCache.flush(err => { if (err) { console.log('flush fail'); @@ -518,9 +516,7 @@ flush(): Promise\ **示例:** ```js -import http from '@ohos.net.http'; -let httpResponseCache = http.createHttpResponseCache(); -http.flush().then(() => { +httpResponseCache.flush().then(() => { console.log('flush success'); }).catch(err => { console.log('flush fail'); @@ -544,8 +540,6 @@ delete(callback: AsyncCallback\): void **示例:** ```js -import http from '@ohos.net.http'; -let httpResponseCache = http.createHttpResponseCache(); httpResponseCache.delete(err => { if (err) { console.log('delete fail'); @@ -571,9 +565,7 @@ delete(): Promise\ **示例:** ```js -import http from '@ohos.net.http'; -let httpResponseCache = http.createHttpResponseCache(); -httpResponseCache.delete().then() => { +httpResponseCache.delete().then(() => { console.log('delete success'); }).catch(err => { console.log('delete fail'); 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 64856eec56fd372f4e04dc535bcab402805de742..f64a19f131c68ca1bae5cafecafabad6d257cd69 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 @@ -157,7 +157,6 @@ connection.getAllNets(function (error, nets) { }); ``` - ## connection.getAllNets getAllNets(): Promise<Array<NetHandle>> @@ -379,7 +378,6 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` - ## connection.reportNetConnected reportNetConnected(netHandle: NetHandle): Promise<void> @@ -412,7 +410,6 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` - ## connection.reportNetDisconnected reportNetDisconnected(netHandle: NetHandle, callback: AsyncCallback<void>): void @@ -441,7 +438,6 @@ connection.getDefaultNet().then(function (netHandle) { }); ``` - ## connection.reportNetDisconnected reportNetDisconnected(netHandle: NetHandle): Promise<void> @@ -532,7 +528,6 @@ connection.getAddressesByName(host).then(function (addresses) { }) ``` - ## connection.enableAirplaneMode enableAirplaneMode(callback: AsyncCallback\): void @@ -581,7 +576,6 @@ connection.enableAirplaneMode().then(function (error) { }) ``` - ## connection.disableAirplaneMode disableAirplaneMode(callback: AsyncCallback\): void @@ -630,7 +624,6 @@ connection.disableAirplaneMode().then(function (error) { }) ``` - ## connection.createNetConnection createNetConnection(netSpecifier?: NetSpecifier, timeout?: number): NetConnection @@ -887,33 +880,50 @@ bindSocket(socketParam: TCPSocket \| UDPSocket, callback: AsyncCallback\): **示例:** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; + let socketType = "TCPSocket"; if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp, (error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(udp, function (error, data) { - console.log(JSON.stringify(error)) - console.log(JSON.stringify(data)) + console.log(JSON.stringify(data)) }); + netHandle.bindSocket(udp,(error, data)=>{ + if (error) { + console.log(JSON.stringify(error)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` ### bindSocket9+ @@ -939,31 +949,50 @@ bindSocket(socketParam: TCPSocket \| UDPSocket): Promise\; **示例:** ```js -connection.getDefaultNet().then(function (netHandle) { +import socket from "@ohos.net.socket"; +connection.getDefaultNet().then((netHandle)=>{ var tcp = socket.constructTCPSocketInstance(); var udp = socket.constructUDPSocketInstance(); - let socketType = "xxxx"; - if(socketType == "TCPSocket") { + let socketType = "TCPSocket"; + if (socketType == "TCPSocket") { tcp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) + if (err) { + console.log('bind fail'); + } + netHandle.bindSocket(tcp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) } else { + let callback = value => { + console.log(TAG + "on message, message:" + value.message + ", remoteInfo:" + value.remoteInfo); + } udp.on('message', callback); udp.bind({ - address: "xxxx", port: xxxx, family: xxxx + address: '192.168.xx.xxx', port: xxxx, family: 1 }, err => { + if (err) { + console.log('bind fail'); + } udp.on('message', (data) => { - console.log(JSON.stringify(data)) - }); - netHandle.bindSocket(tcp).then(err, data) { - console.log(JSON.stringify(data)) - }); + console.log(JSON.stringify(data)); + }) + netHandle.bindSocket(udp).then((err, data) => { + if (err) { + console.log(JSON.stringify(err)); + } else { + console.log(JSON.stringify(data)); + } + }) }) - } -} + } +}) ``` ### getAddressesByName 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 9e935e0de03f5c5b88a0c8c450b3da3f1dfc4080..89c93f3517458ae22b4ab31358a957d64a62a27a 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 @@ -499,7 +499,7 @@ getSharingState(type: SharingIfaceType, callback: AsyncCallback\ { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); @@ -534,7 +534,7 @@ getSharingState(type: SharingIfaceType): Promise\ ```js import SharingIfaceType from '@ohos.net.sharing' -sharing.getSharingIfaces(SharingIfaceType.SHARING_WIFI).then(data => { +sharing.getSharingState(SharingIfaceType.SHARING_WIFI).then(data => { console.log(JSON.stringify(data)); }).catch(error => { console.log(JSON.stringify(error)); @@ -563,8 +563,8 @@ getSharableRegexes(type: SharingIfaceType, callback: AsyncCallback\ { +import SharingIfaceType from '@ohos.net.sharing' +sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI, (error, data) => { console.log(JSON.stringify(error)); console.log(JSON.stringify(data)); }); @@ -605,7 +605,7 @@ sharing.getSharableRegexes(SharingIfaceType.SHARING_WIFI).then(data => { }); ``` -## on('sharingStateChange') +## sharing.on('sharingStateChange') on(type: 'sharingStateChange', callback: Callback\): void @@ -633,7 +633,7 @@ sharing.on('sharingStateChange', (error, data) => { }); ``` -## off('sharingStateChange') +## sharing.off('sharingStateChange') off(type: 'sharingStateChange', callback?: Callback\): void @@ -661,7 +661,7 @@ sharing.off('sharingStateChange', (error, data) => { }); ``` -## on('interfaceSharingStateChange') +## sharing.on('interfaceSharingStateChange') on(type: 'interfaceSharingStateChange', callback: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -689,7 +689,7 @@ sharing.on('interfaceSharingStateChange', (error, data) => { }); ``` -## off('interfaceSharingStateChange') +## sharing.off('interfaceSharingStateChange') off(type: 'interfaceSharingStateChange', callback?: Callback\<{ type: SharingIfaceType, iface: string, state: SharingIfaceState }>): void @@ -717,7 +717,7 @@ sharing.off('interfaceSharingStateChange', (error, data) => { }); ``` -## on('sharingUpstreamChange') +## sharing.on('sharingUpstreamChange') on(type: 'sharingUpstreamChange', callback: Callback\): void @@ -745,7 +745,7 @@ sharing.on('sharingUpstreamChange', (error, data) => { }); ``` -## off('sharingUpstreamChange') +## sharing.off('sharingUpstreamChange') off(type: 'sharingUpstreamChange', callback?: Callback\): void 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 3f6380ee0c42f2846b7d5a48dff14fed921361cb..a18ece3bef4b4aab2c6c1a108a23dc48dba781d7 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-socket.md +++ b/zh-cn/application-dev/reference/apis/js-apis-socket.md @@ -1507,7 +1507,6 @@ bind\(address: NetAddress, callback: AsyncCallback\): void **示例:** ```js -let tls = socket.constructTLSSocketInstance(); tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); @@ -1551,7 +1550,6 @@ bind\(address: NetAddress\): Promise **示例:** ```js -let tls = socket.constructTLSSocketInstance(); let promise = tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}); promise.then(() => { console.log('bind success'); @@ -1584,7 +1582,6 @@ getState\(callback: AsyncCallback\): void **示例:** ```js -let tls = socket.constructTLSSocketInstance(); let promise = tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); @@ -1625,7 +1622,6 @@ getState\(\): Promise **示例:** ```js -let tls = socket.constructTLSSocketInstance(); tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); @@ -1667,7 +1663,6 @@ setExtraOptions\(options: TCPExtraOptions, callback: AsyncCallback\): voi **示例:** ```js -let tls = socket.constructTLSSocketInstance(); tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); @@ -1725,7 +1720,6 @@ setExtraOptions\(options: TCPExtraOptions\): Promise **示例:** ```js -let tls = socket.constructTLSSocketInstance(); tls.bind({address: '192.168.xx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); @@ -1789,15 +1783,14 @@ connect(options: TLSConnectOptions, callback: AsyncCallback\): void **示例:** ```js -let tls = socket.constructTLSSocketInstance(); // Two way authentication -tls.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { +let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication +tlsTwoWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); return; } console.log('bind success'); }); -let Protocol = socket.Protocol; let options = { ALPNProtocols: ["spdy/1", "http/1.1"], address: { @@ -1810,15 +1803,15 @@ let options = { cert: "xxxx", ca: ["xxxx"], passwd: "xxxx", - protocols: [Protocol.TLSv12], + protocols: [socket.Protocol.TLSv12], useRemoteCipherPrefer: true, - signatureAlgorithms: rsa_pss_rsae_sha256:ECDSA+SHA25, - cipherSuite: AES256-SHA256, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", }, }; -tls.connect(options, (err, data) => { - console.info(err); - console.info(data); +tlsTwoWay.connect(options, (err, data) => { + console.error(err); + console.log(data); }); let tlsOneWay = socket.constructTLSSocketInstance(); // One way authentication @@ -1837,12 +1830,12 @@ let oneWayOptions = { }, secureOptions: { ca: ["xxxx","xxxx"], - cipherSuite: AES256-SHA256, + cipherSuite: "AES256-SHA256", }, }; -tlsOneWay.connect(options, (err, data) => { - console.info(err); - console.info(data); +tlsOneWay.connect(oneWayOptions, (err, data) => { + console.error(err); + console.log(data); }); ``` @@ -1890,15 +1883,14 @@ connect(options: TLSConnectOptions): Promise\ **示例:** ```js -let tls = socket.constructTLSSocketInstance(); // Two way authentication -tls.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { +let tlsTwoWay = socket.constructTLSSocketInstance(); // Two way authentication +tlsTwoWay.bind({address: '192.168.xxx.xxx', port: xxxx, family: 1}, err => { if (err) { console.log('bind fail'); return; } console.log('bind success'); }); -let Protocol = socket.Protocol; let options = { ALPNProtocols: ["spdy/1", "http/1.1"], address: { @@ -1911,14 +1903,14 @@ let options = { cert: "xxxx", ca: ["xxxx"], passwd: "xxxx", - protocols: [Protocol.TLSv12], + protocols: [socket.Protocol.TLSv12], useRemoteCipherPrefer: true, - signatureAlgorithms: rsa_pss_rsae_sha256:ECDSA+SHA25, - cipherSuite: AES256-SHA256, + signatureAlgorithms: "rsa_pss_rsae_sha256:ECDSA+SHA256", + cipherSuite: "AES256-SHA256", }, }; -tls.connect(options).then(data => { - console.info(data); +tlsTwoWay.connect(options).then(data => { + console.log(data); }).catch(err => { console.error(err); }); @@ -1939,11 +1931,11 @@ let oneWayOptions = { }, secureOptions: { ca: ["xxxx","xxxx"], - cipherSuite: AES256-SHA256, + cipherSuite: "AES256-SHA256", }, }; tlsOneWay.connect(oneWayOptions).then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2074,7 +2066,7 @@ getCertificate():Promise\<[X509CertRawData](#x509certrawdata9)> ```js tls.getCertificate().then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2138,7 +2130,7 @@ getRemoteCertificate():Promise\<[X509CertRawData](#x509certrawdata9)> ```js tls.getRemoteCertificate().then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2204,7 +2196,7 @@ getProtocol():Promise\ ```js tls.getProtocol().then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2272,7 +2264,7 @@ getCipherSuite(): Promise\> ```js tls.getCipherSuite().then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2336,7 +2328,7 @@ getSignatureAlgorithms(): Promise\> ```js tls.getSignatureAlgorithms().then(data => { - console.info(data); + console.log(data); }).catch(err => { console.error(err); }); @@ -2499,7 +2491,7 @@ TLS连接的操作。 | -------------- | ------------------------------------- | --- |-------------- | | address | [NetAddress](#netaddress) | 是 | 网关地址。 | | secureOptions | [TLSSecureOptions](#tlssecureoptions9) | 是 | TLS安全相关操作。| -| ALPNProtocols | Array\ | 是 | ALPN协议。 | +| ALPNProtocols | Array\ | 否 | ALPN协议。 | ## TLSSecureOptions9+