有奖捉虫:办公协同&微信生态&物联网文档专题 HOT
BatchResponse 是利用 http.batch 批量发起 HTTP 请求得到的请求结果。

字段

字段
类型
描述
error
string
错误,不为空则表示请求出错。
response
Response
请求结果

样例

批量发起请求并获得结果:
import http from 'pts/http';

export default function () {
const responses = http.batch(
[
{
method: 'GET',
url: 'http://httpbin.org/get?a=1',
headers: { a: '1, 2, 3' },
query: { b: '2' },
},
{
method: 'GET',
url: 'http://httpbin.org/get?a=1',
headers: { a: '1, 2, 3' },
query: { b: '2' },
},
],
{
parallel: 1,
},
);

// 200 OK
// 200 OK
for (const resp of responses) {
console.log(resp.response.status);
}
}