Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
OpenHarmony
Docs
提交
27a20ea5
D
Docs
项目概览
OpenHarmony
/
Docs
大约 2 年 前同步成功
通知
161
Star
293
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看板
提交
27a20ea5
编写于
5月 11, 2023
作者:
X
xujie
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
socket 和 fetch 接口参数拆分
Signed-off-by:
N
xujie
<
xujie223@huawei.com
>
上级
79c87ed9
变更
2
显示空白变更内容
内联
并排
Showing
2 changed file
with
48 addition
and
23 deletion
+48
-23
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
+25
-16
zh-cn/application-dev/reference/apis/js-apis-system-network.md
.../application-dev/reference/apis/js-apis-system-network.md
+23
-7
未找到文件。
zh-cn/application-dev/reference/apis/js-apis-system-fetch.md
浏览文件 @
27a20ea5
...
...
@@ -25,23 +25,8 @@ fetch(Object): void
**参数:**
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| url | string | 是 | 资源地址。 |
| data | string
\|
Object | 否 | 请求的参数,可选类型是字符串或者json对象。详见表 data与Content-Type关系。 |
| header | Object | 否 | 设置请求的header。 |
| method | string | 否 | 请求方法默认为GET,可选值为:OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE。 |
| responseType | string | 否 | 默认会根据服务器返回header中的Content-Type确定返回类型,支持文本和json格式。详见success返回值。 |
| success | Function | 否 | 接口调用成功的回调函数,返回值为
[
FetchResponse
](
#fetchresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
| complete | Function | 否 | 接口调用结束的回调函数。 |
**表1**
data与Content-Type关系
| options | FetchOptions | 是 | 调用参数。 |
| data | Content-Type | 说明 |
| -------- | -------- | -------- |
| string | 不设置 | Content-Type默认为
text/plain,data值作为请求的body。 |
| string | 任意
Type | data值作为请求的body。 |
| Object | 不设置 | Content-Type默认为application/x-www-form-urlencoded,data按照资源地址规则进行encode拼接作为请求的body。 |
| Object | application/x-www-form-urlencoded | data按照资源地址规则进行encode拼接作为请求的body。 |
## FetchResponse<sup>3+</sup>
...
...
@@ -85,6 +70,30 @@ export default {
}
```
## FetchOptions<sup>3+</sup>
**系统能力:**
SystemCapability.Communication.NetStack
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| url | string | 是 | 资源地址。 |
| data | string
\|
Object | 否 | 请求的参数,可选类型是字符串或者json对象。详见表 data与Content-Type关系。 |
| header | Object | 否 | 设置请求的header。 |
| method | string | 否 | 请求方法默认为GET,可选值为:OPTIONS、GET、HEAD、POST、PUT、DELETE、TRACE。 |
| responseType | string | 否 | 默认会根据服务器返回header中的Content-Type确定返回类型,支持文本和json格式。详见success返回值。 |
| success | Function | 否 | 接口调用成功的回调函数,返回值为
[
FetchResponse
](
#fetchresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
| complete | Function | 否 | 接口调用结束的回调函数。 |
**表3**
data与Content-Type关系
| data | Content-Type | 说明 |
| -------- | -------- | -------- |
| string | 不设置 | Content-Type默认为
text/plain,data值作为请求的body。 |
| string | 任意
Type | data值作为请求的body。 |
| Object | 不设置 | Content-Type默认为application/x-www-form-urlencoded,data按照资源地址规则进行encode拼接作为请求的body。 |
| Object | application/x-www-form-urlencoded | data按照资源地址规则进行encode拼接作为请求的body。 |
> **说明:**
> 默认支持https,如果要支持http,需要在config.json里增加network标签,属性标识 "cleartextTraffic": true。即:
...
...
zh-cn/application-dev/reference/apis/js-apis-system-network.md
浏览文件 @
27a20ea5
...
...
@@ -23,7 +23,7 @@ ohos.permission.GET_NETWORK_INFO
## network.getType<sup>3+</sup>
getType(
Object
): void
getType(
options?:GetTypeOptions
): void
获取当前设备的网络类型。
...
...
@@ -33,9 +33,7 @@ getType(Object): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| success | Function | 否 | 接口调用成功的回调函数,返回值为
[
NetworkResponse
](
#networkresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
| complete | Function | 否 | 接口调用结束的回调函数。 |
| options | GetTypeOptions | 否 | 可选参数。 |
fail返回值:
...
...
@@ -73,8 +71,7 @@ subscribe(Object): void
| 参数名 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| success | Function | 否 | 网络发生变化的回调函数,返回值为
[
NetworkResponse
](
#networkresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
| options | SubscribeOptions | 否 | 可选参数。 |
fail返回值:
...
...
@@ -128,3 +125,22 @@ export default {
| -------- | -------- | -------- | -------- |
| metered | boolean | 否 |是否按照流量计费。 |
| type | string | 是|网络类型,可能的值有2g,3g,4g,5g,wifi,none等。 |
## GetTypeOptions<sup>3+</sup>
**系统能力:**
SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| success | Function | 否 | 接口调用成功的回调函数,返回值为
[
NetworkResponse
](
#networkresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
| complete | Function | 否 | 接口调用结束的回调函数。 |
## SubscribeOptions<sup>3+</sup>
**系统能力:**
SystemCapability.Communication.NetManager.Core
| 名称 | 类型 | 必填 | 说明 |
| -------- | -------- | -------- | -------- |
| success | Function | 否 | 网络发生变化的回调函数,返回值为
[
NetworkResponse
](
#networkresponse
)
|
| fail | Function | 否 | 接口调用失败的回调函数。 |
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录