菜单
文档breadcrumb arrow Grafana k6breadcrumb arrow JavaScript APIbreadcrumb arrow k6/httpbreadcrumb arrow put( url, [body], [params] )
开源

put( url, [body], [params] )

参数类型描述
urlstring / HTTP URL请求 URL (例如 http://example.com)。
body (可选)string / object / ArrayBuffer请求体;对象将被 x-www-form-urlencoded 编码。
params (可选)object包含额外请求参数的 Params 对象。

返回值

类型描述
ResponseHTTP Response 对象。

示例

JavaScript
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);
}