No results for ""

Powered byAlgolia

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

Parameter Type Description
url string Request URL (e.g.
body string / object Request body; objects will be x-www-form-urlencoded.
params (optional) object Params object containing additional request parameters


Type Description
Response HTTP Response object.


Using to perform a user login at an E-commerce site:

import http from 'k6/http';
import { check, fail } from 'k6';

export let options = { maxRedirects: 10 };

const baseURL = '';

export default function() {
  // Fetch the login page, with the login HTML form
  let res = http.get(baseURL + '/user/login');
  // Extract hidden value needed to POST form
  let formBuildID = res.body.match('name="form_build_id" value="(.*)"')[1];
  // Create an Object containing the form data
  let formdata = {
    name: 'testuser1',
    pass: 'testuser1',
    form_build_id: formBuildID,
    form_id: 'user_login',
    op: 'Log in',
  let headers = { 'Content-Type': 'application/x-www-form-urlencoded' };
  // Send login request
  res = + '/user/login', formdata, { headers: headers });
  // Verify that we ended up on the user page
  check(res, {
    'login succeeded': res => res.url == `${baseURL}/users/testuser1`,
  }) || fail('login failed');