Response 是发起请求后获得的请求结果。
字段
字段 | 类型 | 描述 |
body | string | 服务器返回的响应 |
contentLength | number | 服务器响应体长度 |
headers | Record<string, string> | 服务器响应的 HTTP 头 |
proto | string | 协议,如 "HTTP/1.0" |
request | 为获得此响应而发送的请求 | |
responseTimeMS | number | 请求的响应时间,单位为毫秒 |
status | string | 来自服务器响应的 HTTP 状态消息,如 "200 OK" |
statusCode | number | 来自服务器响应的 HTTP 状态代码,如 200 |
方法
方法 | 返回类型 | 描述 |
any | 将 Response.body 反序列化为 json |
样例
import http from 'pts/http';export default function () {const req = {method: 'post',url: 'http://mockhttpbin.pts.svc.cluster.local/post',headers: { 'Content-Type': 'application/json' },query: { a: '1' },body: { user_id: '12345' },};const resp = http.do(req);console.log(resp.json()); // [Object object]console.log(resp.json().args.a); // 1console.log(resp.json().json.user_id); // 12345}