put( url, [body], [params] )
参数 | 类型 | 描述 |
---|---|---|
url | string / HTTP URL | 请求 URL (例如 http://example.com )。 |
body (可选) | string / object / ArrayBuffer | 请求体;对象将被 x-www-form-urlencoded 编码。 |
params (可选) | object | 包含额外请求参数的 Params 对象。 |
返回值
类型 | 描述 |
---|---|
Response | HTTP Response 对象。 |
示例
import http from 'k6/http';
const url = 'https://quickpizza.grafana.com/api/put';
export default function () {
const headers = { 'Content-Type': 'application/json' };
const data = { name: 'Bert' };
const res = http.put(url, JSON.stringify(data), { headers: headers });
console.log(JSON.parse(res.body).name);
}