No results for ""

Powered byAlgolia

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

suggest edits
ParameterTypeDescription
urlstringRequest URL (e.g. http://example.com).
bodystring / objectRequest body; objects will be x-www-form-urlencoded.
params (optional)objectParams object containing additional request parameters

Returns

TypeDescription
ResponseHTTP Response object.

Example

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.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.post(url, data, {headers: headers});
  console.log(JSON.parse(res.body).form.name);
};