Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Tonvia
Docs
提交
b2436fb0
D
Docs
项目概览
Tonvia
/
Docs
与 Fork 源项目一致
Fork自
OpenHarmony / Docs
通知
1
Star
0
Fork
0
代码
文件
提交
分支
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,发现更多精彩内容 >>
提交
b2436fb0
编写于
3月 01, 2023
作者:
Y
Yangys
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Solving Problems
Signed-off-by:
N
Yangys
<
yangyousheng@huawei.com
>
上级
0c733bb3
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
521 addition
and
170 deletion
+521
-170
zh-cn/application-dev/connectivity/http-request.md
zh-cn/application-dev/connectivity/http-request.md
+34
-18
zh-cn/application-dev/reference/apis/js-apis-http.md
zh-cn/application-dev/reference/apis/js-apis-http.md
+367
-18
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
.../application-dev/reference/apis/js-apis-net-connection.md
+30
-14
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
+28
-28
zh-cn/application-dev/reference/apis/js-apis-net-policy.md
zh-cn/application-dev/reference/apis/js-apis-net-policy.md
+18
-18
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
+5
-5
zh-cn/application-dev/reference/apis/js-apis-system-network.md
.../application-dev/reference/apis/js-apis-system-network.md
+7
-5
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
+0
-41
zh-cn/application-dev/reference/errorcodes/errorcode-net-socket.md
...lication-dev/reference/errorcodes/errorcode-net-socket.md
+2
-2
zh-cn/readme/网络管理子系统.md
zh-cn/readme/网络管理子系统.md
+30
-21
未找到文件。
zh-cn/application-dev/connectivity/http-request.md
浏览文件 @
b2436fb0
...
@@ -18,32 +18,41 @@ HTTP数据请求功能主要由http模块提供。
...
@@ -18,32 +18,41 @@ HTTP数据请求功能主要由http模块提供。
| ----------------------------------------- | ----------------------------------- |
| ----------------------------------------- | ----------------------------------- |
| createHttp() | 创建一个http请求。 |
| createHttp() | 创建一个http请求。 |
| request() | 根据URL地址,发起HTTP网络请求。 |
| request() | 根据URL地址,发起HTTP网络请求。 |
| request2()
<sup>
10+
</sup>
| 根据URL地址,发起HTTP网络请求并返回流式响应|
| destroy() | 中断请求任务。 |
| destroy() | 中断请求任务。 |
| on(type: 'headersReceive') | 订阅HTTP Response Header 事件。 |
| on(type: 'headersReceive') | 订阅HTTP Response Header 事件。 |
| off(type: 'headersReceive') | 取消订阅HTTP Response Header 事件。 |
| off(type: 'headersReceive') | 取消订阅HTTP Response Header 事件。 |
| once
\(
'headersReceive'
\)
<sup>
8+
</sup>
| 订阅HTTP Response Header 事件,但是只触发一次。|
| on
\(
'dataReceive'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收事件。 |
| off
\(
'dataReceive'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收事件。 |
| on
\(
'dataEnd'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收完毕事件。 |
| off
\(
'dataEnd'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收完毕事件。 |
| on
\(
'dataProgress'
\)
<sup>
10+
</sup>
| 订阅HTTP流式响应数据接收进度事件。 |
| off
\(
'dataProgress'
\)
<sup>
10+
</sup>
| 取消订阅HTTP流式响应数据接收进度事件。 |
## 开发步骤
## 开发步骤
1.
import需要的http模块。
1.
从@ohos.net.http.d.ts中导入http命名空间。
2.
创建一个HTTP请求,返回一个HttpRequest对象。
2.
调用createHttp()方法,创建一个HttpRequest对象。
3.
(可选)订阅HTTP响应头。
3.
调用该对象的on()方法,订阅http响应头事件,此接口会比request请求先返回。可以根据业务需要订阅此消息。
4.
根据URL地址,发起HTTP网络请求。
4.
调用该对象的request()方法,传入http请求的url地址和可选参数,发起网络请求。
5.
(可选)处理HTTP响应头和HTTP网络请求的返回结果。
5.
按照实际业务需要,解析返回结果。
6.
调用该对象的off()方法,取消订阅http响应头事件。
7.
当该请求使用完毕时,调用destroy()方法主动销毁。
```
js
```
js
// 引入包名
import
http
from
'
@ohos.net.http
'
;
import
http
from
'
@ohos.net.http
'
;
// 每一个httpRequest对应一个
http
请求任务,不可复用
// 每一个httpRequest对应一个
HTTP
请求任务,不可复用
let
httpRequest
=
http
.
createHttp
();
let
httpRequest
=
http
.
createHttp
();
// 用于订阅HTTP响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
// 用于订阅http响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
// 从API 8开始,使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
// 从API 8开始,使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
httpRequest
.
on
(
'
headersReceive
'
,
(
header
)
=>
{
httpRequest
.
on
(
'
headersReceive
'
,
(
header
)
=>
{
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
header
));
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
header
));
});
});
httpRequest
.
request
(
httpRequest
.
request
(
// 填写
http请求的url
地址,可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
// 填写
HTTP请求的URL
地址,可以带参数也可以不带参数。URL地址需要开发者自定义。请求的参数可以在extraData中指定
"
EXAMPLE_URL
"
,
"
EXAMPLE_URL
"
,
{
{
method
:
http
.
RequestMethod
.
POST
,
// 可选,默认为http.RequestMethod.GET
method
:
http
.
RequestMethod
.
POST
,
// 可选,默认为http.RequestMethod.GET
...
@@ -55,19 +64,26 @@ httpRequest.request(
...
@@ -55,19 +64,26 @@ httpRequest.request(
extraData
:
{
extraData
:
{
"
data
"
:
"
data to send
"
,
"
data
"
:
"
data to send
"
,
},
},
connectTimeout
:
60000
,
// 可选,默认为60s
expectDataType
:
http
.
HttpDataType
.
STRING
,
// 可选,指定返回数据的类型
readTimeout
:
60000
,
// 可选,默认为60s
usingCache
:
true
,
// 可选,默认为true
priority
:
1
,
// 可选,默认为1
connectTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProxy
:
false
,
//可选,默认不使用网络代理,自API 10开始支持该属性
},
(
err
,
data
)
=>
{
},
(
err
,
data
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
// data.result为
http
响应内容,可根据业务需要进行解析
// data.result为
HTTP
响应内容,可根据业务需要进行解析
console
.
info
(
'
Result:
'
+
data
.
result
);
console
.
info
(
'
Result:
'
+
JSON
.
stringify
(
data
.
result
)
);
console
.
info
(
'
code:
'
+
data
.
responseCode
);
console
.
info
(
'
code:
'
+
JSON
.
stringify
(
data
.
responseCode
)
);
// data.header为
http
响应头,可根据业务需要进行解析
// data.header为
HTTP
响应头,可根据业务需要进行解析
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
data
.
header
));
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
data
.
header
));
console
.
info
(
'
cookies:
'
+
data
.
cookies
);
// 8+
console
.
info
(
'
cookies:
'
+
JSON
.
stringify
(
data
.
cookies
)
);
// 8+
}
else
{
}
else
{
console
.
info
(
'
error:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
error:
'
+
JSON
.
stringify
(
err
));
// 该请求不再使用,调用destroy方法主动销毁。
// 取消订阅HTTP响应头事件
httpRequest
.
off
(
'
headersReceive
'
);
// 当该请求使用完毕时,调用destroy方法主动销毁。
httpRequest
.
destroy
();
httpRequest
.
destroy
();
}
}
}
}
...
...
zh-cn/application-dev/reference/apis/js-apis-http.md
浏览文件 @
b2436fb0
...
@@ -16,6 +16,7 @@ import http from '@ohos.net.http';
...
@@ -16,6 +16,7 @@ import http from '@ohos.net.http';
## 完整示例
## 完整示例
```
js
```
js
// 引入包名
import
http
from
'
@ohos.net.http
'
;
import
http
from
'
@ohos.net.http
'
;
// 每一个httpRequest对应一个HTTP请求任务,不可复用
// 每一个httpRequest对应一个HTTP请求任务,不可复用
...
@@ -44,16 +45,19 @@ httpRequest.request(
...
@@ -44,16 +45,19 @@ httpRequest.request(
connectTimeout
:
60000
,
// 可选,默认为60000ms
connectTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
readTimeout
:
60000
,
// 可选,默认为60000ms
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProtocol
:
http
.
HttpProtocol
.
HTTP1_1
,
// 可选,协议类型默认值由系统自动指定
usingProxy
:
false
,
//可选,默认不使用网络代理,自API 10开始支持该属性
},
(
err
,
data
)
=>
{
},
(
err
,
data
)
=>
{
if
(
!
err
)
{
if
(
!
err
)
{
// data.result为HTTP响应内容,可根据业务需要进行解析
// data.result为HTTP响应内容,可根据业务需要进行解析
console
.
info
(
'
Result:
'
+
data
.
result
);
console
.
info
(
'
Result:
'
+
JSON
.
stringify
(
data
.
result
)
);
console
.
info
(
'
code:
'
+
data
.
responseCode
);
console
.
info
(
'
code:
'
+
JSON
.
stringify
(
data
.
responseCode
)
);
// data.header为HTTP响应头,可根据业务需要进行解析
// data.header为HTTP响应头,可根据业务需要进行解析
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
data
.
header
));
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
data
.
header
));
console
.
info
(
'
cookies:
'
+
data
.
cookies
);
// 8+
console
.
info
(
'
cookies:
'
+
JSON
.
stringify
(
data
.
cookies
)
);
// 8+
}
else
{
}
else
{
console
.
info
(
'
error:
'
+
JSON
.
stringify
(
err
));
console
.
info
(
'
error:
'
+
JSON
.
stringify
(
err
));
// 取消订阅HTTP响应头事件
httpRequest
.
off
(
'
headersReceive
'
);
// 当该请求使用完毕时,调用destroy方法主动销毁。
// 当该请求使用完毕时,调用destroy方法主动销毁。
httpRequest
.
destroy
();
httpRequest
.
destroy
();
}
}
...
@@ -136,7 +140,7 @@ httpRequest.request("EXAMPLE_URL", (err, data) => {
...
@@ -136,7 +140,7 @@ httpRequest.request("EXAMPLE_URL", (err, data) => {
### request
### request
request
\(
url: string, options: HttpRequestOptions, callback: AsyncCallback<HttpResponse
\>\)
:void
request
\(
url: string, options: HttpRequestOptions, callback: AsyncCallback
\
<
HttpResponse
\>\)
:void
根据URL地址和相关配置项,发起HTTP网络请求,使用callback方式作为异步方法。
根据URL地址和相关配置项,发起HTTP网络请求,使用callback方式作为异步方法。
...
@@ -219,7 +223,7 @@ httpRequest.request("EXAMPLE_URL",
...
@@ -219,7 +223,7 @@ httpRequest.request("EXAMPLE_URL",
### request
### request
request
\(
url: string, options? : HttpRequestOptions
\)
: Promise<HttpResponse
\>
request
\(
url: string, options? : HttpRequestOptions
\)
: Promise
\
<
HttpResponse
\>
根据URL地址,发起HTTP网络请求,使用Promise方式作为异步方法。
根据URL地址,发起HTTP网络请求,使用Promise方式作为异步方法。
...
@@ -317,6 +321,209 @@ destroy\(\): void
...
@@ -317,6 +321,209 @@ destroy\(\): void
httpRequest
.
destroy
();
httpRequest
.
destroy
();
```
```
### request2<sup>10+</sup>
request2(url: string, callback: AsyncCallback
<void>
): void
根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
| 2300003 | URL using bad/illegal format or missing URL. |
| 2300007 | Couldn't connect to server. |
| 2300028 | Timeout was reached. |
| 2300052 | Server returned nothing (no headers, no data). |
| 2300999 | Unknown Other Error. |
>**错误码说明:**
> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。
> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:[curl错误码](https://curl.se/libcurl/c/libcurl-errors.html)
**示例:**
```
js
httpRequest
.
request2
(
"
EXAMPLE_URL
"
,
(
err
)
=>
{
if
(
!
err
)
{
console
.
info
(
request2
OK
!
);
}
else
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
}
})
```
### request2<sup>10+</sup>
request2(url: string, options: HttpRequestOptions, callback: AsyncCallback
<void>
): void
根据URL地址和相关配置项,发起HTTP网络请求并返回流式响应,使用callback方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ---------------------------------------------- | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| options | HttpRequestOptions | 是 | 参考
[
HttpRequestOptions
](
#httprequestoptions
)
。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
| 2300001 | Unsupported protocol. |
| 2300003 | URL using bad/illegal format or missing URL. |
| 2300005 | Couldn't resolve proxy name. |
| 2300006 | Couldn't resolve host name. |
| 2300007 | Couldn't connect to server. |
| 2300008 | Weird server reply. |
| 2300009 | Access denied to remote resource. |
| 2300016 | Error in the HTTP2 framing layer. |
| 2300018 | Transferred a partial file. |
| 2300023 | Failed writing received data to disk/application. |
| 2300025 | Upload failed. |
| 2300026 | Failed to open/read local data from file/application. |
| 2300027 | Out of memory. |
| 2300028 | Timeout was reached. |
| 2300047 | Number of redirects hit maximum amount. |
| 2300052 | Server returned nothing (no headers, no data). |
| 2300055 | Failed sending data to the peer. |
| 2300056 | Failure when receiving data from the peer. |
| 2300058 | Problem with the local SSL certificate. |
| 2300059 | Couldn't use specified SSL cipher. |
| 2300060 | SSL peer certificate or SSH remote key was not OK. |
| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.|
| 2300063 | Maximum file size exceeded. |
| 2300070 | Disk full or allocation exceeded. |
| 2300073 | Remote file already exists. |
| 2300077 | Problem with the SSL CA cert (path? access rights?). |
| 2300078 | Remote file not found. |
| 2300094 | An authentication function returned an error. |
| 2300999 | Unknown Other Error. |
>**错误码说明:**
> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。
> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:[curl错误码](https://curl.se/libcurl/c/libcurl-errors.html)
**示例:**
```
js
httpRequest
.
request2
(
"
EXAMPLE_URL
"
,
{
method
:
http
.
RequestMethod
.
GET
,
header
:
{
'
Content-Type
'
:
'
application/json
'
},
readTimeout
:
60000
,
connectTimeout
:
60000
},
(
err
)
=>
{
if
(
!
err
)
{
console
.
info
(
request2
OK
!
);
}
else
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
}
})
```
### request2<sup>10+</sup>
request2
\(
url: string, options? : HttpRequestOptions
\)
: Promise
\<
void
\>
根据URL地址,发起HTTP网络请求并返回流式响应,使用Promise方式作为异步方法。
**需要权限**
:ohos.permission.INTERNET
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| ------- | ------------------ | ---- | ----------------------------------------------- |
| url | string | 是 | 发起网络请求的URL地址。 |
| options | HttpRequestOptions | 否 | 参考
[
HttpRequestOptions
](
#httprequestoptions
)
。 |
**返回值:**
| 类型 | 说明 |
| :------------------------------------- | :-------------------------------- |
| Promise
\<
void
\>
| 以Promise形式返回发起请求的结果。 |
**错误码:**
| 错误码ID | 错误信息 |
|---------|-------------------------------------------------------|
| 401 | Parameter error. |
| 201 | Permission denied. |
| 2300001 | Unsupported protocol. |
| 2300003 | URL using bad/illegal format or missing URL. |
| 2300005 | Couldn't resolve proxy name. |
| 2300006 | Couldn't resolve host name. |
| 2300007 | Couldn't connect to server. |
| 2300008 | Weird server reply. |
| 2300009 | Access denied to remote resource. |
| 2300016 | Error in the HTTP2 framing layer. |
| 2300018 | Transferred a partial file. |
| 2300023 | Failed writing received data to disk/application. |
| 2300025 | Upload failed. |
| 2300026 | Failed to open/read local data from file/application. |
| 2300027 | Out of memory. |
| 2300028 | Timeout was reached. |
| 2300047 | Number of redirects hit maximum amount. |
| 2300052 | Server returned nothing (no headers, no data). |
| 2300055 | Failed sending data to the peer. |
| 2300056 | Failure when receiving data from the peer. |
| 2300058 | Problem with the local SSL certificate. |
| 2300059 | Couldn't use specified SSL cipher. |
| 2300060 | SSL peer certificate or SSH remote key was not OK. |
| 2300061 | Unrecognized or bad HTTP Content or Transfer-Encoding.|
| 2300063 | Maximum file size exceeded. |
| 2300070 | Disk full or allocation exceeded. |
| 2300073 | Remote file already exists. |
| 2300077 | Problem with the SSL CA cert (path? access rights?). |
| 2300078 | Remote file not found. |
| 2300094 | An authentication function returned an error. |
| 2300999 | Unknown Other Error. |
>**错误码说明:**
> 以上错误码的详细介绍参见[HTTP错误码](../errorcodes/errorcode-net-http.md)。
> HTTP 错误码映射关系:2300000 + curl错误码。更多常用错误码,可参考:
**示例:**
```
js
let
promise
=
httpRequest
.
request
(
"
EXAMPLE_URL
"
,
{
method
:
http
.
RequestMethod
.
GET
,
connectTimeout
:
60000
,
readTimeout
:
60000
,
header
:
{
'
Content-Type
'
:
'
application/json
'
}
});
promise
.
then
(()
=>
{
console
.
info
(
request2
OK
!
);
}).
catch
((
err
)
=>
{
console
.
info
(
"
request2 ERROR : err =
"
+
JSON
.
stringify
(
err
));
});
```
### on\('headerReceive'\)
### on\('headerReceive'\)
on
\(
type: 'headerReceive', callback: AsyncCallback<Object
\>\)
: void
on
\(
type: 'headerReceive', callback: AsyncCallback<Object
\>\)
: void
...
@@ -443,7 +650,148 @@ httpRequest.once('headersReceive', (header) => {
...
@@ -443,7 +650,148 @@ httpRequest.once('headersReceive', (header) => {
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
header
));
console
.
info
(
'
header:
'
+
JSON
.
stringify
(
header
));
});
});
```
```
### on\('dataReceive'\)<sup>10+</sup>
on
\(
type: 'dataReceive', callback: Callback
\<
ArrayBuffer
\>\)
: void
订阅HTTP流式响应数据接收事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataReceive'。 |
| callback | AsyncCallback
\<
ArrayBuffer
\>
| 是 | 回调函数。 |
**示例:**
```
js
httpRequest
.
on
(
'
dataReceive
'
,
(
data
)
=>
{
console
.
info
(
'
dataReceive length:
'
+
JSON
.
stringify
(
data
.
byteLength
));
});
```
### off\('dataReceive'\)<sup>10+</sup>
off
\(
type: 'dataReceive', callback?: Callback
\<
ArrayBuffer
\>\)
: void
取消订阅HTTP流式响应数据接收事件。
>![](public_sys-resources/icon-note.gif) **说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataReceive'。 |
| callback | Callback
\<
ArrayBuffer
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataReceive
'
);
```
### on\('dataEnd'\)<sup>10+</sup>
on
\(
type: 'dataEnd', callback: Callback
\<
void
\>\)
: void
订阅HTTP流式响应数据接收完毕事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataEnd'。 |
| callback | AsyncCallback
\<
void
\>
| 是 | 回调函数。 |
**示例:**
```
js
httpRequest
.
on
(
'
dataReceive
'
,
()
=>
{
console
.
info
(
'
Receive dataEnd!
'
);
});
```
### off\('dataEnd'\)<sup>10+</sup>
off(type: 'dataEnd', callback?: Callback
\<
void
\>
): void
取消订阅HTTP流式响应数据接收完毕事件。
>![](public_sys-resources/icon-note.gif) **说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataEnd'。 |
| callback | Callback
\<
void
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataEnd
'
);
```
### on\('dataProgress'\)<sup>10+</sup>
on
\(
type: 'dataProgress', callback: Callback
\<
{ receiveSize: number, totalSize: number }
\>\)
: void
订阅HTTP流式响应数据接收进度事件。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ----------------------- | ---- | --------------------------------- |
| type | string | 是 | 订阅的事件类型,'dataProgress'。 |
| callback | AsyncCallback
\<
{ receiveSize: number, totalSize: number }
\>
| 是 | 回调函数。 |
**示例:**
```
js
httpRequest
.
on
(
'
dataProgress
'
,
(
data
)
=>
{
if
(
!
err
)
{
console
.
info
(
'
dataProgress:
'
+
JSON
.
stringify
(
data
));
}
});
```
### off\('dataProgress'\)<sup>10+</sup>
off(type: 'dataProgress', callback?: Callback
\<
{ receiveSize: number, totalSize: number }
\>
): void
取消订阅HTTP流式响应数据接收进度事件。
>![](public_sys-resources/icon-note.gif) **说明:**
>可以指定传入on中的callback取消一个订阅,也可以不指定callback清空所有订阅。
**系统能力**
:SystemCapability.Communication.NetStack
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | ------------------ | ---- | -------------------------------------- |
| type | string | 是 | 取消订阅的事件类型:'dataProgress'。 |
| callback | Callback
\<
{ receiveSize: number, totalSize: number }
\>
| 否 | 回调函数。 |
**示例:**
```
js
httpRequest
.
off
(
'
dataProgress
'
);
```
## HttpRequestOptions
## HttpRequestOptions
发起请求可选参数的类型和取值范围。
发起请求可选参数的类型和取值范围。
...
@@ -454,13 +802,14 @@ httpRequest.once('headersReceive', (header) => {
...
@@ -454,13 +802,14 @@ httpRequest.once('headersReceive', (header) => {
| -------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| -------------- | --------------------------------------------- | ---- | ------------------------------------------------------------ |
| method |
[
RequestMethod
](
#requestmethod
)
| 否 | 请求方式。 |
| method |
[
RequestMethod
](
#requestmethod
)
| 否 | 请求方式。 |
| extraData | string
\|
Object
\|
ArrayBuffer
<sup>
6+
</sup>
| 否 | 发送请求的额外数据。
<br
/>
- 当HTTP请求为POST、PUT等方法时,此字段为HTTP请求的content。
<br
/>
- 当HTTP请求为GET、OPTIONS、DELETE、TRACE、CONNECT等方法时,此字段为HTTP请求的参数补充,参数内容会拼接到URL中进行发送。
<sup>
6+
</sup><br
/>
- 开发者传入string对象,开发者需要自行编码,将编码后的string传入。
<sup>
6+
</sup>
|
| extraData | string
\|
Object
\|
ArrayBuffer
<sup>
6+
</sup>
| 否 | 发送请求的额外数据。
<br
/>
- 当HTTP请求为POST、PUT等方法时,此字段为HTTP请求的content。
<br
/>
- 当HTTP请求为GET、OPTIONS、DELETE、TRACE、CONNECT等方法时,此字段为HTTP请求的参数补充,参数内容会拼接到URL中进行发送。
<sup>
6+
</sup><br
/>
- 开发者传入string对象,开发者需要自行编码,将编码后的string传入。
<sup>
6+
</sup>
|
| expectDataType
<sup>
9+
</sup>
|
[
HttpDataType
](
#httpdatatype9
)
| 否 | 指定返回数据的类型。如果设置了此参数,系统将优先返回指定的类型。 |
| expectDataType
<sup>
9+
</sup>
|
[
HttpDataType
](
#httpdatatype9
)
| 否 | 指定返回数据的类型。如果设置了此参数,系统将优先返回指定的类型。 |
| usingCache
<sup>
9+
</sup>
| boolean | 否 | 是否使用缓存,默认为true。 |
| usingCache
<sup>
9+
</sup>
| boolean | 否 | 是否使用缓存,默认为true。 |
| priority
<sup>
9+
</sup>
| number | 否 | 优先级,范围
\[
1,1000],默认是1。 |
| priority
<sup>
9+
</sup>
| number | 否 | 优先级,范围
\[
1,1000],默认是1。 |
| header | Object | 否 | HTTP请求头字段。默认{'Content-Type': 'application/json'}。 |
| header | Object | 否 | HTTP请求头字段。默认{'Content-Type': 'application/json'}。 |
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 |
| readTimeout | number | 否 | 读取超时时间。单位为毫秒(ms),默认为60000ms。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| connectTimeout | number | 否 | 连接超时时间。单位为毫秒(ms),默认为60000ms。 |
| usingProtocol
<sup>
9+
</sup>
|
[
HttpProtocol
](
#httpprotocol9
)
| 否 | 使用协议。默认值由系统自动指定。 |
| usingProtocol
<sup>
9+
</sup>
|
[
HttpProtocol
](
#httpprotocol9
)
| 否 | 使用协议。默认值由系统自动指定。 |
| usingProxy
<sup>
10+
</sup>
| boolean
\|
Object | 否 | 是否使用HTTP代理,默认为false,不使用代理。
<br
/>
- 当usingProxy为布尔类型true时,使用默认网络代理。
<br
/>
- 当usingProxy为object类型时,使用指定网络代理。 |
## RequestMethod
## RequestMethod
...
@@ -587,10 +936,10 @@ flush(callback: AsyncCallback\<void>): void
...
@@ -587,10 +936,10 @@ flush(callback: AsyncCallback\<void>): void
```
js
```
js
httpResponseCache
.
flush
(
err
=>
{
httpResponseCache
.
flush
(
err
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
'
flush fail
'
);
console
.
info
(
'
flush fail
'
);
return
;
return
;
}
}
console
.
log
(
'
flush success
'
);
console
.
info
(
'
flush success
'
);
});
});
```
```
...
@@ -612,9 +961,9 @@ flush(): Promise\<void>
...
@@ -612,9 +961,9 @@ flush(): Promise\<void>
```
js
```
js
httpResponseCache
.
flush
().
then
(()
=>
{
httpResponseCache
.
flush
().
then
(()
=>
{
console
.
log
(
'
flush success
'
);
console
.
info
(
'
flush success
'
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
'
flush fail
'
);
console
.
info
(
'
flush fail
'
);
});
});
```
```
...
@@ -637,10 +986,10 @@ delete(callback: AsyncCallback\<void>): void
...
@@ -637,10 +986,10 @@ delete(callback: AsyncCallback\<void>): void
```
js
```
js
httpResponseCache
.
delete
(
err
=>
{
httpResponseCache
.
delete
(
err
=>
{
if
(
err
)
{
if
(
err
)
{
console
.
log
(
'
delete fail
'
);
console
.
info
(
'
delete fail
'
);
return
;
return
;
}
}
console
.
log
(
'
delete success
'
);
console
.
info
(
'
delete success
'
);
});
});
```
```
### delete<sup>9+</sup>
### delete<sup>9+</sup>
...
@@ -661,9 +1010,9 @@ delete(): Promise\<void>
...
@@ -661,9 +1010,9 @@ delete(): Promise\<void>
```
js
```
js
httpResponseCache
.
delete
().
then
(()
=>
{
httpResponseCache
.
delete
().
then
(()
=>
{
console
.
log
(
'
delete success
'
);
console
.
info
(
'
delete success
'
);
}).
catch
(
err
=>
{
}).
catch
(
err
=>
{
console
.
log
(
'
delete fail
'
);
console
.
info
(
'
delete fail
'
);
});
});
```
```
...
...
zh-cn/application-dev/reference/apis/js-apis-net-connection.md
浏览文件 @
b2436fb0
...
@@ -146,6 +146,8 @@ getGlobalHttpProxy(callback: AsyncCallback\<HttpProxy>): void
...
@@ -146,6 +146,8 @@ getGlobalHttpProxy(callback: AsyncCallback\<HttpProxy>): void
获取网络的全局代理配置信息,使用callback方式作为异步方法。
获取网络的全局代理配置信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
**参数:**
...
@@ -176,6 +178,8 @@ getGlobalHttpProxy(): Promise\<HttpProxy>;
...
@@ -176,6 +178,8 @@ getGlobalHttpProxy(): Promise\<HttpProxy>;
获取网络的全局代理配置信息,使用Promise方式作为异步方法。
获取网络的全局代理配置信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**返回值:**
**返回值:**
...
@@ -207,6 +211,8 @@ setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): void
...
@@ -207,6 +211,8 @@ setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): void
设置网络全局Http代理配置信息,使用callback方式作为异步方法。
设置网络全局Http代理配置信息,使用callback方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
...
@@ -231,12 +237,12 @@ setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): void
...
@@ -231,12 +237,12 @@ setGlobalHttpProxy(httpProxy: HttpProxy, callback: AsyncCallback\<void>): void
**示例:**
**示例:**
```
js
```
js
let
ExclusionList
=
"
"
let
exclusionStr
=
"
192.168,baidu.com
"
let
array
=
ExclusionList
.
split
(
'
,
'
);
let
exclusionArray
=
exclusionStr
.
split
(
'
,
'
);
let
httpProxy
=
{
let
httpProxy
=
{
host
:
"
host
"
,
host
:
"
192.168.xx.xxx
"
,
port
:
1
,
port
:
8080
,
parsedExclusionList
:
a
rray
exclusionList
:
exclusionA
rray
}
}
connection
.
setGlobalHttpProxy
(
httpProxy
,
(
error
,
data
)
=>
{
connection
.
setGlobalHttpProxy
(
httpProxy
,
(
error
,
data
)
=>
{
console
.
info
(
JSON
.
stringify
(
error
));
console
.
info
(
JSON
.
stringify
(
error
));
...
@@ -250,6 +256,8 @@ setGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>;
...
@@ -250,6 +256,8 @@ setGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>;
设置网络全局Http代理配置信息,使用Promise方式作为异步方法。
设置网络全局Http代理配置信息,使用Promise方式作为异步方法。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
...
@@ -279,12 +287,12 @@ setGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>;
...
@@ -279,12 +287,12 @@ setGlobalHttpProxy(httpProxy: HttpProxy): Promise\<void>;
**示例:**
**示例:**
```
js
```
js
let
ExclusionList
=
"
"
let
exclusionStr
=
"
192.168,baidu.com
"
let
array
=
ExclusionList
.
split
(
'
,
'
);
let
exclusionArray
=
exclusionStr
.
split
(
'
,
'
);
let
httpProxy
=
{
let
httpProxy
=
{
host
:
"
host
"
,
host
:
"
192.168.xx.xxx
"
,
port
:
1
,
port
:
8080
,
parsedExclusionList
:
a
rray
exclusionList
:
exclusionA
rray
}
}
connection
.
setGlobalHttpProxy
(
httpProxy
).
then
((
error
,
data
)
=>
{
connection
.
setGlobalHttpProxy
(
httpProxy
).
then
((
error
,
data
)
=>
{
console
.
info
(
JSON
.
stringify
(
data
));
console
.
info
(
JSON
.
stringify
(
data
));
...
@@ -317,10 +325,10 @@ getAppNet(callback: AsyncCallback\<NetHandle>): void
...
@@ -317,10 +325,10 @@ getAppNet(callback: AsyncCallback\<NetHandle>): void
**示例:**
**示例:**
```
js
```
js
connection
.
getAppNet
(
function
(
error
,
data
)
)
{
connection
.
getAppNet
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
}
}
)
```
```
## connection.getAppNet<sup>9+</sup>
## connection.getAppNet<sup>9+</sup>
...
@@ -799,6 +807,8 @@ enableAirplaneMode(callback: AsyncCallback\<void>): void
...
@@ -799,6 +807,8 @@ enableAirplaneMode(callback: AsyncCallback\<void>): void
**系统接口**
:此接口为系统接口。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
**参数:**
...
@@ -830,6 +840,8 @@ enableAirplaneMode(): Promise\<void>
...
@@ -830,6 +840,8 @@ enableAirplaneMode(): Promise\<void>
**系统接口**
:此接口为系统接口。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**返回值:**
**返回值:**
...
@@ -861,6 +873,8 @@ disableAirplaneMode(callback: AsyncCallback\<void>): void
...
@@ -861,6 +873,8 @@ disableAirplaneMode(callback: AsyncCallback\<void>): void
**系统接口**
:此接口为系统接口。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**参数:**
**参数:**
...
@@ -892,6 +906,8 @@ disableAirplaneMode(): Promise\<void>
...
@@ -892,6 +906,8 @@ disableAirplaneMode(): Promise\<void>
**系统接口**
:此接口为系统接口。
**系统接口**
:此接口为系统接口。
**需要权限**
:ohos.permission.CONNECTIVITY_INTERNAL
**系统能力**
:SystemCapability.Communication.NetManager.Core
**系统能力**
:SystemCapability.Communication.NetManager.Core
**返回值:**
**返回值:**
...
@@ -1807,7 +1823,7 @@ connection.getDefaultNet().then(function (netHandle) {
...
@@ -1807,7 +1823,7 @@ connection.getDefaultNet().then(function (netHandle) {
| BEARER_WIFI | 1 | Wi-Fi网络。 |
| BEARER_WIFI | 1 | Wi-Fi网络。 |
| BEARER_ETHERNET | 3 | 以太网网络。 |
| BEARER_ETHERNET | 3 | 以太网网络。 |
## HttpProxy
## HttpProxy
<sup>10+</sup>
网络全局代理配置信息
网络全局代理配置信息
...
@@ -1817,7 +1833,7 @@ connection.getDefaultNet().then(function (netHandle) {
...
@@ -1817,7 +1833,7 @@ connection.getDefaultNet().then(function (netHandle) {
| ------ | ------ | --- |------------------------- |
| ------ | ------ | --- |------------------------- |
| host | string | 否 | 代理服务器主机名。 |
| host | string | 否 | 代理服务器主机名。 |
| port | number | 否 | 主机端口。 |
| port | number | 否 | 主机端口。 |
|
parsedE
xclusionList | Array
<string>
| 否 | 不使用代理服务器的屏蔽列表。 |
|
e
xclusionList | Array
<string>
| 否 | 不使用代理服务器的屏蔽列表。 |
## NetSpecifier
## NetSpecifier
...
...
zh-cn/application-dev/reference/apis/js-apis-net-ethernet.md
浏览文件 @
b2436fb0
...
@@ -57,7 +57,7 @@ ethernet.setIfaceConfig("eth0", {
...
@@ -57,7 +57,7 @@ ethernet.setIfaceConfig("eth0", {
domain
:
"
2.2.2.2
"
domain
:
"
2.2.2.2
"
},
(
error
)
=>
{
},
(
error
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
"
setIfaceConfig callback error =
"
+
error
);
console
.
log
(
"
setIfaceConfig callback error =
"
+
JSON
.
stringify
(
error
)
);
}
else
{
}
else
{
console
.
log
(
"
setIfaceConfig callback ok
"
);
console
.
log
(
"
setIfaceConfig callback ok
"
);
}
}
...
@@ -116,7 +116,7 @@ ethernet.setIfaceConfig("eth0", {
...
@@ -116,7 +116,7 @@ ethernet.setIfaceConfig("eth0", {
}).
then
(()
=>
{
}).
then
(()
=>
{
console
.
log
(
"
setIfaceConfig promiss ok
"
);
console
.
log
(
"
setIfaceConfig promiss ok
"
);
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
setIfaceConfig promiss error =
"
+
error
);
console
.
log
(
"
setIfaceConfig promiss error =
"
+
JSON
.
stringify
(
error
)
);
});
});
```
```
...
@@ -155,15 +155,15 @@ getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>):
...
@@ -155,15 +155,15 @@ getIfaceConfig(iface: string, callback: AsyncCallback\<InterfaceConfiguration>):
```
js
```
js
ethernet
.
getIfaceConfig
(
"
eth0
"
,
(
error
,
value
)
=>
{
ethernet
.
getIfaceConfig
(
"
eth0
"
,
(
error
,
value
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
"
getIfaceConfig callback error =
"
+
error
);
console
.
log
(
"
getIfaceConfig callback error =
"
+
JSON
.
stringify
(
error
)
);
}
else
{
}
else
{
console
.
log
(
"
getIfaceConfig callback mode =
"
+
value
.
mode
);
console
.
log
(
"
getIfaceConfig callback mode =
"
+
JSON
.
stringify
(
value
.
mode
)
);
console
.
log
(
"
getIfaceConfig callback ipAddr =
"
+
value
.
ipAddr
);
console
.
log
(
"
getIfaceConfig callback ipAddr =
"
+
JSON
.
stringify
(
value
.
ipAddr
)
);
console
.
log
(
"
getIfaceConfig callback route =
"
+
value
.
route
);
console
.
log
(
"
getIfaceConfig callback route =
"
+
JSON
.
stringify
(
value
.
route
)
);
console
.
log
(
"
getIfaceConfig callback gateway =
"
+
value
.
gateway
);
console
.
log
(
"
getIfaceConfig callback gateway =
"
+
JSON
.
stringify
(
value
.
gateway
)
);
console
.
log
(
"
getIfaceConfig callback netMask =
"
+
value
.
netMask
);
console
.
log
(
"
getIfaceConfig callback netMask =
"
+
JSON
.
stringify
(
value
.
netMask
)
);
console
.
log
(
"
getIfaceConfig callback dnsServers =
"
+
value
.
dnsServers
);
console
.
log
(
"
getIfaceConfig callback dnsServers =
"
+
JSON
.
stringify
(
value
.
dnsServers
)
);
console
.
log
(
"
getIfaceConfig callback domain =
"
+
value
.
domain
);
console
.
log
(
"
getIfaceConfig callback domain =
"
+
JSON
.
stringify
(
value
.
domain
)
);
}
}
});
});
```
```
...
@@ -207,15 +207,15 @@ getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
...
@@ -207,15 +207,15 @@ getIfaceConfig(iface: string): Promise\<InterfaceConfiguration>
```
js
```
js
ethernet
.
getIfaceConfig
(
"
eth0
"
).
then
((
data
)
=>
{
ethernet
.
getIfaceConfig
(
"
eth0
"
).
then
((
data
)
=>
{
console
.
log
(
"
getIfaceConfig promiss mode =
"
+
data
.
mode
);
console
.
log
(
"
getIfaceConfig promiss mode =
"
+
JSON
.
stringify
(
data
.
mode
)
);
console
.
log
(
"
getIfaceConfig promiss ipAddr =
"
+
data
.
ipAddr
);
console
.
log
(
"
getIfaceConfig promiss ipAddr =
"
+
JSON
.
stringify
(
data
.
ipAddr
)
);
console
.
log
(
"
getIfaceConfig promiss route =
"
+
data
.
route
);
console
.
log
(
"
getIfaceConfig promiss route =
"
+
JSON
.
stringify
(
data
.
route
)
);
console
.
log
(
"
getIfaceConfig promiss gateway =
"
+
data
.
gateway
);
console
.
log
(
"
getIfaceConfig promiss gateway =
"
+
JSON
.
stringify
(
data
.
gateway
)
);
console
.
log
(
"
getIfaceConfig promiss netMask =
"
+
data
.
netMask
);
console
.
log
(
"
getIfaceConfig promiss netMask =
"
+
JSON
.
stringify
(
data
.
netMask
)
);
console
.
log
(
"
getIfaceConfig promiss dnsServers =
"
+
data
.
dnsServers
);
console
.
log
(
"
getIfaceConfig promiss dnsServers =
"
+
JSON
.
stringify
(
data
.
dnsServers
)
);
console
.
log
(
"
getIfaceConfig promiss domain =
"
+
data
.
domain
);
console
.
log
(
"
getIfaceConfig promiss domain =
"
+
JSON
.
stringify
(
data
.
domain
)
);
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
getIfaceConfig promiss error =
"
+
error
);
console
.
log
(
"
getIfaceConfig promiss error =
"
+
JSON
.
stringify
(
error
)
);
});
});
```
```
...
@@ -254,9 +254,9 @@ isIfaceActive(iface: string, callback: AsyncCallback\<number>): void
...
@@ -254,9 +254,9 @@ isIfaceActive(iface: string, callback: AsyncCallback\<number>): void
```
js
```
js
ethernet
.
isIfaceActive
(
"
eth0
"
,
(
error
,
value
)
=>
{
ethernet
.
isIfaceActive
(
"
eth0
"
,
(
error
,
value
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
"
whether2Activate callback error =
"
+
error
);
console
.
log
(
"
whether2Activate callback error =
"
+
JSON
.
stringify
(
error
)
);
}
else
{
}
else
{
console
.
log
(
"
whether2Activate callback =
"
+
value
);
console
.
log
(
"
whether2Activate callback =
"
+
JSON
.
stringify
(
value
)
);
}
}
});
});
```
```
...
@@ -300,9 +300,9 @@ isIfaceActive(iface: string): Promise\<number>
...
@@ -300,9 +300,9 @@ isIfaceActive(iface: string): Promise\<number>
```
js
```
js
ethernet
.
isIfaceActive
(
"
eth0
"
).
then
((
data
)
=>
{
ethernet
.
isIfaceActive
(
"
eth0
"
).
then
((
data
)
=>
{
console
.
log
(
"
isIfaceActive promiss =
"
+
data
);
console
.
log
(
"
isIfaceActive promiss =
"
+
JSON
.
stringify
(
data
)
);
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
isIfaceActive promiss error =
"
+
error
);
console
.
log
(
"
isIfaceActive promiss error =
"
+
JSON
.
stringify
(
error
)
);
});
});
```
```
...
@@ -337,11 +337,11 @@ getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void
...
@@ -337,11 +337,11 @@ getAllActiveIfaces(callback: AsyncCallback\<Array\<string>>): void
```
js
```
js
ethernet
.
getAllActiveIfaces
((
error
,
value
)
=>
{
ethernet
.
getAllActiveIfaces
((
error
,
value
)
=>
{
if
(
error
)
{
if
(
error
)
{
console
.
log
(
"
getAllActiveIfaces callback error =
"
+
error
);
console
.
log
(
"
getAllActiveIfaces callback error =
"
+
JSON
.
stringify
(
error
)
);
}
else
{
}
else
{
console
.
log
(
"
getAllActiveIfaces callback value.length =
"
+
value
.
length
);
console
.
log
(
"
getAllActiveIfaces callback value.length =
"
+
JSON
.
stringify
(
value
.
length
)
);
for
(
let
i
=
0
;
i
<
value
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
value
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces callback =
"
+
value
[
i
]
);
console
.
log
(
"
getAllActiveIfaces callback =
"
+
JSON
.
stringify
(
value
[
i
])
);
}
}
}
}
});
});
...
@@ -377,12 +377,12 @@ getAllActiveIfaces(): Promise\<Array\<string>>
...
@@ -377,12 +377,12 @@ getAllActiveIfaces(): Promise\<Array\<string>>
```
js
```
js
ethernet
.
getAllActiveIfaces
().
then
((
data
)
=>
{
ethernet
.
getAllActiveIfaces
().
then
((
data
)
=>
{
console
.
log
(
"
getAllActiveIfaces promiss data.length =
"
+
data
.
length
);
console
.
log
(
"
getAllActiveIfaces promiss data.length =
"
+
JSON
.
stringify
(
data
.
length
)
);
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
for
(
let
i
=
0
;
i
<
data
.
length
;
i
++
)
{
console
.
log
(
"
getAllActiveIfaces promiss =
"
+
data
[
i
]
);
console
.
log
(
"
getAllActiveIfaces promiss =
"
+
JSON
.
stringify
(
data
[
i
])
);
}
}
}).
catch
(
error
=>
{
}).
catch
(
error
=>
{
console
.
log
(
"
getAllActiveIfaces promiss error =
"
+
error
);
console
.
log
(
"
getAllActiveIfaces promiss error =
"
+
JSON
.
stringify
(
error
)
);
});
});
```
```
...
...
zh-cn/application-dev/reference/apis/js-apis-net-policy.md
浏览文件 @
b2436fb0
...
@@ -84,7 +84,7 @@ setBackgroundPolicy(isAllowed: boolean): Promise\<void>
...
@@ -84,7 +84,7 @@ setBackgroundPolicy(isAllowed: boolean): Promise\<void>
**示例:**
**示例:**
```
js
```
js
policy
.
setBackgroundPolicy
(
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
((
error
,
data
)
{
policy
.
setBackgroundPolicy
(
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -151,7 +151,7 @@ isBackgroundAllowed(): Promise\<boolean>;
...
@@ -151,7 +151,7 @@ isBackgroundAllowed(): Promise\<boolean>;
**示例:**
**示例:**
```
js
```
js
policy
.
isBackgroundAllowed
().
then
((
error
,
data
)
{
policy
.
isBackgroundAllowed
().
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -236,7 +236,7 @@ setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
...
@@ -236,7 +236,7 @@ setPolicyByUid(uid: number, policy: NetUidPolicy): Promise\<void>;
let
param
=
{
let
param
=
{
uid
:
Number
.
parseInt
(
this
.
firstParam
),
policy
:
Number
.
parseInt
(
this
.
currentNetUidPolicy
)
uid
:
Number
.
parseInt
(
this
.
firstParam
),
policy
:
Number
.
parseInt
(
this
.
currentNetUidPolicy
)
}
}
policy
.
setPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
),
Number
.
parseInt
(
this
.
currentNetUidPolicy
)).
then
((
error
,
data
)
{
policy
.
setPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
),
Number
.
parseInt
(
this
.
currentNetUidPolicy
)).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -313,7 +313,7 @@ getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
...
@@ -313,7 +313,7 @@ getPolicyByUid(uid: number): Promise\<NetUidPolicy>;
**示例:**
**示例:**
```
js
```
js
policy
.
getPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
)).
then
((
error
,
data
)
{
policy
.
getPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
)).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -390,7 +390,7 @@ function getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
...
@@ -390,7 +390,7 @@ function getUidsByPolicy(policy: NetUidPolicy): Promise\<Array\<number>>;
**示例:**
**示例:**
```
js
```
js
policy
.
getUidsByPolicy
(
Number
.
parseInt
(
this
.
firstParam
)).
then
((
error
,
data
)
{
policy
.
getUidsByPolicy
(
Number
.
parseInt
(
this
.
firstParam
)).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -456,7 +456,7 @@ getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
...
@@ -456,7 +456,7 @@ getNetQuotaPolicies(): Promise\<Array\<NetQuotaPolicy>>;
**示例:**
**示例:**
```
js
```
js
policy
.
getNetQuotaPolicies
().
then
((
error
,
data
)
{
policy
.
getNetQuotaPolicies
().
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -541,7 +541,7 @@ let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this
...
@@ -541,7 +541,7 @@ let param = {netType:Number.parseInt(this.netType), iccid:this.iccid, ident:this
limitBytes
:
Number
.
parseInt
(
this
.
limitBytes
),
lastWarningRemind
:
this
.
lastWarningRemind
,
lastLimitRemind
:
this
.
lastLimitRemind
,
metered
:
Boolean
(
Number
.
parseInt
(
this
.
metered
)),
limitAction
:
this
.
limitAction
};
limitBytes
:
Number
.
parseInt
(
this
.
limitBytes
),
lastWarningRemind
:
this
.
lastWarningRemind
,
lastLimitRemind
:
this
.
lastLimitRemind
,
metered
:
Boolean
(
Number
.
parseInt
(
this
.
metered
)),
limitAction
:
this
.
limitAction
};
this
.
netQuotaPolicyList
.
push
(
param
);
this
.
netQuotaPolicyList
.
push
(
param
);
policy
.
setNetQuotaPolicies
(
this
.
netQuotaPolicyList
).
then
((
error
,
data
)
{
policy
.
setNetQuotaPolicies
(
this
.
netQuotaPolicyList
).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -619,7 +619,7 @@ restoreAllPolicies(iccid: string): Promise\<void>;
...
@@ -619,7 +619,7 @@ restoreAllPolicies(iccid: string): Promise\<void>;
```
js
```
js
this
.
firstParam
=
iccid
;
this
.
firstParam
=
iccid
;
policy
.
restoreAllPolicies
(
this
.
firstParam
).
then
((
error
,
data
){
policy
.
restoreAllPolicies
(
this
.
firstParam
).
then
(
function
(
error
,
data
){
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -706,7 +706,7 @@ isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
...
@@ -706,7 +706,7 @@ isUidNetAllowed(uid: number, isMetered: boolean): Promise\<boolean>;
let
param
=
{
let
param
=
{
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isMetered
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isMetered
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
}
}
policy
.
isUidNetAllowed
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
((
error
,
data
)
{
policy
.
isUidNetAllowed
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -792,7 +792,7 @@ isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
...
@@ -792,7 +792,7 @@ isUidNetAllowed(uid: number, iface: string): Promise\<boolean>;
let
param
=
{
let
param
=
{
uid
:
Number
.
parseInt
(
this
.
firstParam
),
iface
:
this
.
secondParam
uid
:
Number
.
parseInt
(
this
.
firstParam
),
iface
:
this
.
secondParam
}
}
policy
.
isUidNetAllowed
(
Number
.
parseInt
(
this
.
firstParam
),
this
.
secondParam
).
then
((
error
,
data
)
{
policy
.
isUidNetAllowed
(
Number
.
parseInt
(
this
.
firstParam
),
this
.
secondParam
).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -877,7 +877,7 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
...
@@ -877,7 +877,7 @@ setDeviceIdleAllowList(uid: number, isAllowed: boolean): Promise\<void>;
let
param
=
{
let
param
=
{
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isAllowed
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isAllowed
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
}
}
policy
.
setDeviceIdleAllowList
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
((
error
,
data
)
{
policy
.
setDeviceIdleAllowList
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -943,7 +943,7 @@ getDeviceIdleAllowList(): Promise\<Array\<number>>;
...
@@ -943,7 +943,7 @@ getDeviceIdleAllowList(): Promise\<Array\<number>>;
**示例:**
**示例:**
```
js
```
js
policy
.
getDeviceIdleAllowList
().
then
((
error
,
data
)
{
policy
.
getDeviceIdleAllowList
().
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -1021,7 +1021,7 @@ getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
...
@@ -1021,7 +1021,7 @@ getBackgroundPolicyByUid(uid: number): Promise\<NetBackgroundPolicy>;
```
js
```
js
this
.
firstParam
=
uid
this
.
firstParam
=
uid
policy
.
getBackgroundPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
)).
then
((
error
,
data
)
{
policy
.
getBackgroundPolicyByUid
(
Number
.
parseInt
(
this
.
firstParam
)).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -1098,11 +1098,11 @@ resetPolicies(iccid: string): Promise\<void>;
...
@@ -1098,11 +1098,11 @@ resetPolicies(iccid: string): Promise\<void>;
**示例:**
**示例:**
```
js
```
js
policy
.
getUidsByPolicy
(
Number
.
parseInt
(
this
.
firstParam
)).
then
((
error
,
data
)
{
policy
.
getUidsByPolicy
(
Number
.
parseInt
(
this
.
firstParam
)).
then
(
function
(
error
,
data
)
{
})
})
this
.
firstParam
=
iccid
this
.
firstParam
=
iccid
policy
.
resetPolicies
(
this
.
firstParam
).
then
((
error
,
data
)
{
policy
.
resetPolicies
(
this
.
firstParam
).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -1189,7 +1189,7 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType):
...
@@ -1189,7 +1189,7 @@ updateRemindPolicy(netType: NetBearType, iccid: string, remindType: RemindType):
let
param
=
{
let
param
=
{
netType
:
Number
.
parseInt
(
this
.
netType
),
iccid
:
this
.
firstParam
,
remindType
:
this
.
currentRemindType
netType
:
Number
.
parseInt
(
this
.
netType
),
iccid
:
this
.
firstParam
,
remindType
:
this
.
currentRemindType
}
}
policy
.
updateRemindPolicy
(
Number
.
parseInt
(
this
.
netType
),
this
.
firstParam
,
Number
.
parseInt
(
this
.
currentRemindType
)).
then
((
error
,
data
)
{
policy
.
updateRemindPolicy
(
Number
.
parseInt
(
this
.
netType
),
this
.
firstParam
,
Number
.
parseInt
(
this
.
currentRemindType
)).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -1274,7 +1274,7 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>;
...
@@ -1274,7 +1274,7 @@ setPowerSaveAllowList(uid: number, isAllowed: boolean): Promise\<void>;
let
param
=
{
let
param
=
{
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isAllowed
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
uid
:
Number
.
parseInt
(
this
.
firstParam
),
isAllowed
:
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))
}
}
policy
.
setPowerSaveAllowList
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
((
error
,
data
)
{
policy
.
setPowerSaveAllowList
(
Number
.
parseInt
(
this
.
firstParam
),
Boolean
(
Number
.
parseInt
(
this
.
isBoolean
))).
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
@@ -1340,7 +1340,7 @@ getPowerSaveAllowList(): Promise\<Array\<number>>;
...
@@ -1340,7 +1340,7 @@ getPowerSaveAllowList(): Promise\<Array\<number>>;
**示例:**
**示例:**
```
js
```
js
policy
.
getPowerSaveAllowList
().
then
((
error
,
data
)
{
policy
.
getPowerSaveAllowList
().
then
(
function
(
error
,
data
)
{
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
error
))
console
.
log
(
JSON
.
stringify
(
data
))
console
.
log
(
JSON
.
stringify
(
data
))
})
})
...
...
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
浏览文件 @
b2436fb0
...
@@ -45,11 +45,11 @@ fetch(Object): void
...
@@ -45,11 +45,11 @@ fetch(Object): void
## FetchResponse
## FetchResponse
| 参数名 | 类型 | 说明 |
| 参数名 | 类型 |
可读 | 可写 |
说明 |
| -------- | -------- | -------- |
| -------- | -------- | -------- |
-------- | -------- |
| code | number | 表示服务器的状态code。 |
| code | number |
是 | 否 |
表示服务器的状态code。 |
| data | string
\|
Object | 返回数据类型由responseType确定,详见表 responseType与success中data关系。 |
| data | string
\|
Object |
是 | 否 |
返回数据类型由responseType确定,详见表 responseType与success中data关系。 |
| headers | Object | 表示服务器response的所有header。 |
| headers | Object |
是 | 否 |
表示服务器response的所有header。 |
**表2**
responseType与success中data关系
**表2**
responseType与success中data关系
...
...
zh-cn/application-dev/reference/apis/js-apis-system-network.md
浏览文件 @
b2436fb0
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
> **说明:**
> **说明:**
> - 从API Version 7 开始,该接口不再维护,推荐使用新接口[`@ohos.telephony.observer`](js-apis-observer.md)。
> - 从API Version 7 开始,该接口不再维护,推荐使用新接口[`@ohos.telephony.observer`](js-apis-observer.md)。
>
>
> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
> - 本模块首批接口从API version 3开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
...
@@ -122,7 +122,9 @@ export default {
...
@@ -122,7 +122,9 @@ export default {
## NetworkResponse
## NetworkResponse
| 参数名 | 类型 | 说明 |
**系统能力:**
SystemCapability.Communication.NetManager.Core
| -------- | -------- | -------- |
| metered | boolean | 是否按照流量计费。 |
| 参数名 | 类型 | 必填 | 说明 |
| type | string | 网络类型,可能的值有2g,3g,4g,5g,wifi,none等。 |
| -------- | -------- | -------- | -------- |
\ No newline at end of file
| metered | boolean | 否 |是否按照流量计费。 |
| type | string | 是|网络类型,可能的值有2g,3g,4g,5g,wifi,none等。 |
\ No newline at end of file
zh-cn/application-dev/reference/apis/js-apis-webSocket.md
浏览文件 @
b2436fb0
...
@@ -442,11 +442,6 @@ on\(type: 'open', callback: AsyncCallback<Object\>\): void
...
@@ -442,11 +442,6 @@ on\(type: 'open', callback: AsyncCallback<Object\>\): void
| type | string | 是 | 'open':WebSocket的打开事件。 |
| type | string | 是 | 'open':WebSocket的打开事件。 |
| callback | AsyncCallback
\<
Object
\>
| 是 | 回调函数。 |
| callback | AsyncCallback
\<
Object
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|-------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
...
@@ -476,12 +471,6 @@ off\(type: 'open', callback?: AsyncCallback<Object\>\): void
...
@@ -476,12 +471,6 @@ off\(type: 'open', callback?: AsyncCallback<Object\>\): void
| type | string | 是 | 'open':WebSocket的打开事件。 |
| type | string | 是 | 'open':WebSocket的打开事件。 |
| callback | AsyncCallback
\<
Object
\>
| 否 | 回调函数。 |
| callback | AsyncCallback
\<
Object
\>
| 否 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|-------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
@@ -513,12 +502,6 @@ on\(type: 'message', callback: AsyncCallback<string | ArrayBuffer\>\): void
...
@@ -513,12 +502,6 @@ on\(type: 'message', callback: AsyncCallback<string | ArrayBuffer\>\): void
| type | string | 是 | 'message':WebSocket的接收到服务器消息事件。 |
| type | string | 是 | 'message':WebSocket的接收到服务器消息事件。 |
| callback | AsyncCallback
\<
string
\|
ArrayBuffer
<sup>
8+
</sup>
\>
| 是 | 回调函数。 |
| callback | AsyncCallback
\<
string
\|
ArrayBuffer
<sup>
8+
</sup>
\>
| 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|--------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
@@ -548,12 +531,6 @@ off\(type: 'message', callback?: AsyncCallback<string | ArrayBuffer\>\): void
...
@@ -548,12 +531,6 @@ off\(type: 'message', callback?: AsyncCallback<string | ArrayBuffer\>\): void
| type | string | 是 | 'message':WebSocket的接收到服务器消息事件。 |
| type | string | 是 | 'message':WebSocket的接收到服务器消息事件。 |
| callback | AsyncCallback
\<
string
\|
ArrayBuffer
<sup>
8+
</sup>
\>
| 否 | 回调函数。 |
| callback | AsyncCallback
\<
string
\|
ArrayBuffer
<sup>
8+
</sup>
\>
| 否 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|-------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
@@ -605,12 +582,6 @@ off\(type: 'close', callback?: AsyncCallback<\{ code: number, reason: string \}\
...
@@ -605,12 +582,6 @@ off\(type: 'close', callback?: AsyncCallback<\{ code: number, reason: string \}\
| type | string | 是 | 'close':WebSocket的关闭事件。 |
| type | string | 是 | 'close':WebSocket的关闭事件。 |
| callback | AsyncCallback
<
{
code:
number
,
reason:
string
}
>
| 否 | 回调函数。 |
| callback | AsyncCallback
<
{
code:
number
,
reason:
string
}
>
| 否 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|-------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
@@ -634,12 +605,6 @@ on\(type: 'error', callback: ErrorCallback\): void
...
@@ -634,12 +605,6 @@ on\(type: 'error', callback: ErrorCallback\): void
| type | string | 是 | 'error':WebSocket的Error事件。 |
| type | string | 是 | 'error':WebSocket的Error事件。 |
| callback | ErrorCallback | 是 | 回调函数。 |
| callback | ErrorCallback | 是 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|-------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
@@ -668,12 +633,6 @@ off\(type: 'error', callback?: ErrorCallback\): void
...
@@ -668,12 +633,6 @@ off\(type: 'error', callback?: ErrorCallback\): void
| type | string | 是 | 'error':WebSocket的Error事件。 |
| type | string | 是 | 'error':WebSocket的Error事件。 |
| callback | ErrorCallback | 否 | 回调函数。 |
| callback | ErrorCallback | 否 | 回调函数。 |
**错误码:**
| 错误码ID | 错误信息 |
|--------|---------------------------|
| 401 | Parameter error. |
**示例:**
**示例:**
```
js
```
js
...
...
zh-cn/application-dev/reference/errorcodes/errorcode-net-socket.md
浏览文件 @
b2436fb0
...
@@ -54,11 +54,11 @@ No such process.
...
@@ -54,11 +54,11 @@ No such process.
排查进程信息。
排查进程信息。
## 230
0004 Interrupted system call
## 230
1004 系统调用中断
**错误信息**
**错误信息**
Couldn't resolve host name
.
Interrupted system call
.
**错误描述**
**错误描述**
...
...
zh-cn/readme/网络管理子系统.md
浏览文件 @
b2436fb0
...
@@ -72,7 +72,7 @@ foundation/communication/
...
@@ -72,7 +72,7 @@ foundation/communication/
1.
从@ohos.net.sharing中导入sharing命名空间。
1.
从@ohos.net.sharing中导入sharing命名空间。
2.
设定共享类型
2.
设定共享类型
3.
开始共享
3.
开始共享
4.
止共享
4.
停
止共享
```
```
// 引入包名
// 引入包名
import sharing from '@ohos.net.sharing';
import sharing from '@ohos.net.sharing';
...
@@ -92,26 +92,28 @@ sharing.stopSharing(this.sharingType,(err)=>{
...
@@ -92,26 +92,28 @@ sharing.stopSharing(this.sharingType,(err)=>{
1.
从@ohos.net.http.d.ts中导入http命名空间。
1.
从@ohos.net.http.d.ts中导入http命名空间。
2.
调用createHttp()方法,创建一个HttpRequest对象。
2.
调用createHttp()方法,创建一个HttpRequest对象。
3.
调用该对象的on()方法,订阅http响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息。
3.
调用该对象的on()方法,订阅http响应头
事件
,此接口会比request请求先返回。可以根据业务需要订阅此消息。
4.
调用该对象的request()方法,传入http请求的url地址和可选参数,发起网络请求。
4.
调用该对象的request()方法,传入http请求的url地址和可选参数,发起网络请求。
5.
按照实际业务需要,解析返回结果。
5.
按照实际业务需要,解析返回结果。
6.
当该请求使用完毕时,调用destroy()方法主动销毁。
6.
调用该对象的off()方法,取消订阅http响应头事件。
7.
当该请求使用完毕时,调用destroy()方法主动销毁。
```
```
// 引入包名
// 引入包名
import http from '@ohos.net.http';
import http from '@ohos.net.http';
// 每一个httpRequest对应一个
http
请求任务,不可复用
// 每一个httpRequest对应一个
HTTP
请求任务,不可复用
let httpRequest = http.createHttp();
let httpRequest = http.createHttp();
// 用于订阅http响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
// 用于订阅HTTP响应头,此接口会比request请求先返回。可以根据业务需要订阅此消息
httpRequest.on('headersReceive', (data) => {
// 从API 8开始,使用on('headersReceive', Callback)替代on('headerReceive', AsyncCallback)。 8+
console.info('header: ' + data.header);
httpRequest.on('headersReceive', (header) => {
console.info('header: ' + JSON.stringify(header));
});
});
httpRequest.request(
httpRequest.request(
// 填写
http请求的url地址,可以带参数也可以不带参数。URL地址需要开发者自定义。GET
请求的参数可以在extraData中指定
// 填写
HTTP请求的URL地址,可以带参数也可以不带参数。URL地址需要开发者自定义。
请求的参数可以在extraData中指定
"EXAMPLE_URL",
"EXAMPLE_URL",
{
{
method:
'POST', // 可选,默认为“GET”
method:
http.RequestMethod.POST, // 可选,默认为http.RequestMethod.GET
// 开发者根据自身业务需要添加header字段
// 开发者根据自身业务需要添加header字段
header: {
header: {
'Content-Type': 'application/json'
'Content-Type': 'application/json'
...
@@ -120,21 +122,28 @@ httpRequest.request(
...
@@ -120,21 +122,28 @@ httpRequest.request(
extraData: {
extraData: {
"data": "data to send",
"data": "data to send",
},
},
connectTimeout: 60000, // 可选,默认为60000,即60s
expectDataType: http.HttpDataType.STRING, // 可选,指定返回数据的类型
readTimeout: 60000, // 可选,默认为60000,即60s
usingCache: true, // 可选,默认为true
},(err, data) => {
priority: 1, // 可选,默认为1
connectTimeout: 60000, // 可选,默认为60000ms
readTimeout: 60000, // 可选,默认为60000ms
usingProtocol: http.HttpProtocol.HTTP1_1, // 可选,协议类型默认值由系统自动指定
usingProxy: false, //可选,默认不使用网络代理,自API 10开始支持该属性
}, (err, data) => {
if (!err) {
if (!err) {
// data.result为
http
响应内容,可根据业务需要进行解析
// data.result为
HTTP
响应内容,可根据业务需要进行解析
console.info('Result:' +
data.result
);
console.info('Result:' +
JSON.stringify(data.result)
);
console.info('code:' +
data.responseCode
);
console.info('code:' +
JSON.stringify(data.responseCode)
);
// data.header为
http
响应头,可根据业务需要进行解析
// data.header为
HTTP
响应头,可根据业务需要进行解析
console.info('header:' +
data.header
);
console.info('header:' +
JSON.stringify(data.header)
);
console.info('
header:' + data.cookies);
console.info('
cookies:' + JSON.stringify(data.cookies)); // 8+
} else {
} else {
console.info('error:' + err);
console.info('error:' + JSON.stringify(err));
// 取消订阅HTTP响应头事件
httpRequest.off('headersReceive');
// 当该请求使用完毕时,调用destroy方法主动销毁。
httpRequest.destroy();
}
}
// 当该请求使用完毕时,调用destroy()方法主动销毁。
httpRequest.destroy();
}
}
);
);
```
```
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录