request( method, url, [body], [params] )
Returns
Example
Using http.request() to issue a POST request:
import http from 'k6/http';
const url = 'https://quickpizza.grafana.com/api/post';
export default function () {
const data = { name: 'Bert' };
// Using a JSON string as body
let res = http.request('POST', url, JSON.stringify(data), {
headers: { 'Content-Type': 'application/json' },
});
console.log(res.json().name); // Bert
// Using an object as body, the headers will automatically include
// 'Content-Type: application/x-www-form-urlencoded'.
res = http.request('POST', url, data);
console.log(res.body); // name=Bert
}