Based on #1184, the following script:
import http from "k6/http";
export default function () {
let payload = {
data: "something",
another: null ,
};
let resp = http.post("https://httpbin.org/post", payload);
console.log(resp.body);
}
Will produce:
{
"args": {},
"data": "",
"files": {},
"form": {
"another": "<nil>",
"data": "something"
},
"headers": {
"Content-Length": "32",
"Content-Type": "application/x-www-form-urlencoded",
"Host": "httpbin.org",
"User-Agent": "k6/0.26.0-dev (https://k6.io/)"
},
"json": null,
"origin": "46.233.49.37, 46.233.49.37",
"url": "https://httpbin.org/post"
}
As can be seen by httpbin's response, k6 automagically encodes the object as x-www-form-urlencoded, which is due to this lines https://github.com/loadimpact/k6/blob/1d6fb7f668aa089b374ee8ca35de2a34d77d29ce/js/modules/k6/http/request.go#L148-L151
A quick proposal is to check for null and return "" but I am not certain so we need to read some RFCs, probably or something.
Based on #1184, the following script:
Will produce:
{ "args": {}, "data": "", "files": {}, "form": { "another": "<nil>", "data": "something" }, "headers": { "Content-Length": "32", "Content-Type": "application/x-www-form-urlencoded", "Host": "httpbin.org", "User-Agent": "k6/0.26.0-dev (https://k6.io/)" }, "json": null, "origin": "46.233.49.37, 46.233.49.37", "url": "https://httpbin.org/post" }As can be seen by httpbin's response, k6 automagically encodes the object as
x-www-form-urlencoded, which is due to this lines https://github.com/loadimpact/k6/blob/1d6fb7f668aa089b374ee8ca35de2a34d77d29ce/js/modules/k6/http/request.go#L148-L151A quick proposal is to check for
nulland return""but I am not certain so we need to read some RFCs, probably or something.