K6 newbie here, currently working on a load test scenario for an API we have.
This is a request I am using to hit an API endpoint.
const request1 = {
method: "POST",
url: endpointUrl,
body: requestBody,
params: {
headers: {
"Content-Type": "application/json",
"custom-header-1": 'value1',
"custom-header-2": 'value2',
"Accept": "application/json"
}
}
};
const responses = http.batch([request1])
If I execute this request using http.post, everything works as expected.
But using http.batch, I always get back a 415 Media type unsupported back from the server. When checking the request sent to my API using Wireshark, I can see that the content-type being sent is of type x-www-form-urlencoded, and not application/json as defined in my request. The two custom header values I’m sending are also not visible.
Based on their example page K6 batch, I have also tried by defining the request in-line, but the result is the same.
What is missing from my script that my custom content-type isn’t getting picked up by the batch function? As you can see, there is a Requestheaders header that’s an object, but those values should actually be applied on request level.
Thank you.
By providing the content-type as part of the params.headers object, I expect this value to get passed on to the request.

The
requestBodyI was sending was aJsonobject, like the one on their example page. The solution is to call the function withJson.stringify(requestBody)instead.