Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
db13b28b
D
Docs
项目概览
OpenHarmony
/
Docs
11 个月 前同步成功
通知
159
Star
292
Fork
28
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
D
Docs
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
未验证
提交
db13b28b
编写于
12月 08, 2022
作者:
O
openharmony_ci
提交者:
Gitee
12月 08, 2022
浏览文件
操作
浏览文件
下载
差异文件
!12293 修复网络管理js示例代码
Merge pull request !12293 from 刘建东/master
上级
b6acd07c
637c629f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
103 addition
and
90 deletion
+103
-90
zh-cn/application-dev/reference/apis/js-apis-http.md
zh-cn/application-dev/reference/apis/js-apis-http.md
+2
-10
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
.../application-dev/reference/apis/js-apis-net-connection.md
+64
-35
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
+10
-10
zh-cn/application-dev/reference/apis/js-apis-socket.md
zh-cn/application-dev/reference/apis/js-apis-socket.md
+27
-35
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-http.md
浏览文件 @
db13b28b
...
...
@@ -490,8 +490,6 @@ flush(callback: AsyncCallback\<void>): 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\<void>
**示例:**
```
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>): 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\<void>
**示例:**
```
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
'
);
...
...
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
浏览文件 @
db13b28b
...
...
@@ -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>): void
...
...
@@ -581,7 +576,6 @@ connection.enableAirplaneMode().then(function (error) {
})
```
## connection.disableAirplaneMode
disableAirplaneMode(callback: AsyncCallback
\<
void>): 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\<void>):
**示例:**
```
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
))
});
netHandle
.
bindSocket
(
udp
,(
error
,
data
)
=>
{
if
(
error
)
{
console
.
log
(
JSON
.
stringify
(
error
));
}
else
{
console
.
log
(
JSON
.
stringify
(
data
));
}
})
})
}
}
}
)
```
### bindSocket<sup>9+</sup>
...
...
@@ -939,31 +949,50 @@ bindSocket(socketParam: TCPSocket \| UDPSocket): Promise\<void>;
**示例:**
```
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
...
...
zh-cn/application-dev/reference/apis/js-apis-net-sharing.md
浏览文件 @
db13b28b
...
...
@@ -499,7 +499,7 @@ getSharingState(type: SharingIfaceType, callback: AsyncCallback\<SharingIfaceSta
**示例:**
```
js
import
SharingIface
Stat
e
from
'
@ohos.net.sharing
'
import
SharingIface
Typ
e
from
'
@ohos.net.sharing
'
sharing
.
getSharingState
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
,
data
)
=>
{
console
.
log
(
JSON
.
stringify
(
error
));
console
.
log
(
JSON
.
stringify
(
data
));
...
...
@@ -534,7 +534,7 @@ getSharingState(type: SharingIfaceType): Promise\<SharingIfaceState>
```
js
import
SharingIfaceType
from
'
@ohos.net.sharing
'
sharing
.
getSharing
Ifaces
(
SharingIfaceType
.
SHARING_WIFI
).
then
(
data
=>
{
sharing
.
getSharing
State
(
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\<Array\<strin
**示例:**
```
js
import
SharingIface
Stat
e
from
'
@ohos.net.sharing
'
sharing
.
getShar
ingState
(
SharingIfaceType
.
SHARING_WIFI
,
(
error
,
data
)
=>
{
import
SharingIface
Typ
e
from
'
@ohos.net.sharing
'
sharing
.
getShar
ableRegexes
(
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
\<
boolean>): void
...
...
@@ -633,7 +633,7 @@ sharing.on('sharingStateChange', (error, data) => {
});
```
## off('sharingStateChange')
##
sharing.
off('sharingStateChange')
off(type: 'sharingStateChange', callback?: Callback
\<
boolean>): 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
\<
NetHandle>): void
...
...
@@ -745,7 +745,7 @@ sharing.on('sharingUpstreamChange', (error, data) => {
});
```
## off('sharingUpstreamChange')
##
sharing.
off('sharingUpstreamChange')
off(type: 'sharingUpstreamChange', callback?: Callback
\<
NetHandle>): void
...
...
zh-cn/application-dev/reference/apis/js-apis-socket.md
浏览文件 @
db13b28b
...
...
@@ -1507,7 +1507,6 @@ bind\(address: NetAddress, callback: AsyncCallback<void\>\): 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<void\>
**示例:**
```
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<SocketStateBase\>\): 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<SocketStateBase\>
**示例:**
```
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<void\>\): 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<void\>
**示例:**
```
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>): void
**示例:**
```
js
let
tls
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tls
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
let
tls
TwoWay
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tls
TwoWay
.
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
);
tls
TwoWay
.
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
(
o
neWayO
ptions
,
(
err
,
data
)
=>
{
console
.
error
(
err
);
console
.
log
(
data
);
});
```
...
...
@@ -1890,15 +1883,14 @@ connect(options: TLSConnectOptions): Promise\<void>
**示例:**
```
js
let
tls
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tls
.
bind
({
address
:
'
192.168.xxx.xxx
'
,
port
:
xxxx
,
family
:
1
},
err
=>
{
let
tls
TwoWay
=
socket
.
constructTLSSocketInstance
();
// Two way authentication
tls
TwoWay
.
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
);
tls
TwoWay
.
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\<string>
```
js
tls
.
getProtocol
().
then
(
data
=>
{
console
.
info
(
data
);
console
.
log
(
data
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
...
...
@@ -2272,7 +2264,7 @@ getCipherSuite(): Promise\<Array\<string>>
```
js
tls
.
getCipherSuite
().
then
(
data
=>
{
console
.
info
(
data
);
console
.
log
(
data
);
}).
catch
(
err
=>
{
console
.
error
(
err
);
});
...
...
@@ -2336,7 +2328,7 @@ getSignatureAlgorithms(): Promise\<Array\<string>>
```
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
\<
string> |
是
| ALPN协议。 |
| ALPNProtocols | Array
\<
string> |
否
| ALPN协议。 |
## TLSSecureOptions<sup>9+</sup>
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录