# request
发起一个 HTTP 请求。
# 支持说明
应用能力 | Android | iOS | PC | 预览效果 |
---|---|---|---|---|
小程序 | 3.1.0 | 3.1.0 | 3.2.0 | 扫码预览 用BoosHi扫码或PC端点击 |
网页应用 | X | X | X | / |
# 输入
继承标准对象输入,扩展属性描述:
名称 | 数据类型 | 必填 | 默认值 | 描述 |
---|---|---|---|---|
url | string | 是 | 请求地址 示例值:https://api.weizhipin.com/mock/179/api/system/plugins | |
header | object | 否 | {'content-type': 'application/json'} | 请求 Header 示例值:{'content-type': 'application/json'} |
method | string | 否 | GET | 请求方法 示例值:GET 当前仅支持GET、POST 可选值: GET POST PUT OPTIONS HEAD DELETE |
data | string|object|arraybuffer | 否 | 请求数据 示例值:{"noncestr":123} 对于 GET 方法,会将 data 对象转换为 Query string,并拼接至 url 的 Query 部分 对于 POST 方法,如果 header 未指定 content-type,或 header['content-type'] 为 'application/json',则会将 data 进行 JSON 序列化 对于 POST 方法,如果 header['content-type'] 为 'application/x-www-form-urlencoded',则会将 data 对象转换为 Query string,放入请求体中 | |
dataType | string | 否 | json | 请求数据类型待开发 示例值:json |
responseType | string | 否 | text | 响应数据类型,参数值可以是 text 或 arraybuffer待开发 示例值:text 可选值: text arraybuffer |
# 输出
success
返回对象的扩展属性:
名称 | 数据类型 | 描述 |
---|---|---|
statusCode | number | 返回 HTTP 状态码 |
header | object | 返回 HTTP Header |
data | string|object|arraybuffer | 返回数据 |
返回值:RequestTask
,该对象的方法列表如下:
提示
点击下表中的方法名,查看对应API的支持说明、调用方法
方法 | 介绍 |
---|---|
abort() | 中断请求任务 |
# 示例代码
const requestTask = bz.request({
"timeout": 3000,
"url": "https://api.weizhipin.com/mock/179/api/system/plugins",
"data": {
"noncestr": Date.now()
},
"header": {
"content-type": "application/json"
},
"method": "GET",
"dataType": "json",
"responseType": "text",
success(res) {
bz.showModal({
title: '成功',
content: JSON.stringify(res)
})
},
fail(res) {
bz.showModal({
title: '失败',
content: JSON.stringify(res)
})
}
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
success
返回对象示例:
{
"statusCode": 200,
"header": {
"status": "200",
"server": "Tengine",
"content-type": "text/html",
"date": "Sun, 21 Nov 2021 02:51:02 GMT",
"vary": "Accept-Encoding",
"set-cookie": "__ac_nonce=06199b416006255ab57c1; Path=/; Max-Age=1800",
"server-timing": "inner; dur=9,cdn-cache;desc=MISS,edge;dur=0,origin;dur=135",
"x-tt-trace-host": "011d2aece4e92d84a85d7fcea0cc3f2c027b31de29296ecf91fdc235ecdc68b13696f60959c09c485e35660c121656222b2eae610b80d07f266a4c49a1c2611c57a24c2f641bc4e3f3534f19f29108ad6475941944ca55afeca5d20a723beb6b5c",
"x-tt-trace-tag": "id=3;cdn-cache=miss",
"x-tt-trace-id": "00-40677dfb0df306001cc1ab774f000489-40677dfb0df30600-01",
"content-encoding": "identity",
"via": "cache2.cn3641[135,0]",
"timing-allow-origin": "*",
"eagleid": "6f30441616374630628026648e",
"x-net-info.remoteaddr": "111.48.68.224:443",
"x-protocol": "CronetTcp+h2",
"EENet-Request-Http-Channel": "rustChannel",
"EENet-Request-Server-Ip": "",
"EENet-Request-Dns-Cost": "0",
"EENet-Request-Tls-Cost": "0",
"EENet-Request-Tcp-Cost": "0",
"EENet-XRequest-Id": "112",
"request-id": ""
},
"data": "<html><head><meta charset=\"UTF-8\" /></head><body></body><script src='https://sf1-ttcdn-tos.pstatp.com/obj/rc-web-sdk/acrawler.js'></script><script>function _f1(e,t){if(\"string\"!=typeof t)return;var o,n=e+\"=\",r=t.split(/[;&]/);for(var e=0;e<r.length;e++){for(o=r[e];\" \"===o.charAt(0);)o=o.substring(1,o.length);if(0===o.indexOf(n))return o.substring(n.length,o.length)}return\"\"}function _f2(e){return _f1(e,document.cookie)}function _f3(e,t,o){try{o&&(window.sessionStorage&&window.sessionStorage.setItem(e,t),window.localStorage&&window.localStorage.setItem(e,t));var n=31536e6;document.cookie=e+\"=; expires=Mon, 20 Sep 1970 00:00:00 UTC; path=/;\",document.cookie=e+\"=\"+t+\"; expires=\"+new Date((new Date).getTime()+n).toGMTString()+\"; path=/;\"}catch(e){}}window.byted_acrawler.init({aid:99999999,dfp:!0});var __ac_nonce=_f2(\"__ac_nonce\"),__ac_signature=window.byted_acrawler.sign(\"\",__ac_nonce);_f3(\"__ac_signature\",__ac_signature),_f3(\"__ac_referer\",document.referrer||\"__ac_blank\",!0);try{sessionStorage.setItem(\"__ac_ns\",performance.timing.navigationStart)}catch(e){};window.location.reload();</script></html>",
"errMsg": "request:ok"
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# 常见问题
method
必须严格按照枚举值 GET
POST
PUT
OPTIONS
HEAD
DELETE
来进行设置,否则在ios端会出现请求不通的情况,请严格按照规范使用!!!