No results for

Powered byAlgolia

request( method, url, [body], [params] )

suggest edits
ParameterTypeDescription
methodstringRequest method (e.g. POST). Note, the method must be uppercase.
urlstringRequest URL (e.g. http://example.com).
body (optional)string / objectRequest body; objects will be x-www-form-urlencoded.
params (optional)objectParams object containing additional request parameters.

Returns

TypeDescription
ResponseHTTP Response object.

Example

Using http.request() to issue a POST request, logging in to an e-commerce site:

import http from 'k6/http';
export default function () {
const url = 'https://httpbin.org/post';
let headers = { 'Content-Type': 'application/json' };
let data = { name: 'Bert' };
let res = http.request('POST', url, JSON.stringify(data), {
headers: headers,
});
console.log(JSON.parse(res.body).json.name);
headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
res = http.request('POST', url, data, { headers: headers });
console.log(JSON.parse(res.body).form.name);
}