Http batch not using the given content-type

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, everything works fine.

But from http.batch I always get back a 415 from the server, media type unsupported. 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, which seems to be the default. The two custom header values I’m sending are also not visible

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 in advance,

Hi @adrianc137 :wave:

Welcome to the support forum :bowing_man:

I have tried reproducing the issue but was unfortunately unable to…

Here is the test script I’ve used:

import http from 'k6/http';

export default function () {
    const request = {
        method: 'POST',
        url: '',
        body: JSON.stringify({ name: 'Bert' }),
        params: {
            headers: {
                'Content-Type': 'application/json',
                'custom-header-1': 'value1',
                'custom-header-2': 'value2',
                'Accept': 'application/json'

    const responses = http.batch([request])

As you can see, the results are consistent with the request, and the headers are present accordingly:

          /\      |‾‾| /‾‾/   /‾‾/
     /\  /  \     |  |/  /   /  /
    /  \/    \    |     (   /   ‾‾\
   /          \   |  |\  \ |  (‾)  |
  / __________ \  |__| \__\ \_____/ .io

  execution: local
     script: http-batch-headers.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] Request:
POST /post HTTP/1.1
User-Agent: k6/0.47.0 (
Content-Length: 15
Accept: application/json
Content-Type: application/json
Custom-Header-1: value1
Custom-Header-2: value2
Accept-Encoding: gzip

{"name":"Bert"}  group= iter=0 request_id=7ed1feef-76b8-4065-7207-822de4abef81 scenario=default source=http-debug vu=1
INFO[0000] Response:
HTTP/2.0 200 OK
Content-Length: 524
Access-Control-Allow-Credentials: true
Access-Control-Allow-Origin: *
Content-Type: application/json
Date: Tue, 31 Oct 2023 15:42:09 GMT
Server: gunicorn/19.9.0

  "args": {},
  "data": "{\"name\":\"Bert\"}",
  "files": {},
  "form": {},
  "headers": {
    "Accept": "application/json",
    "Content-Length": "15",
    "Content-Type": "application/json",
    "Custom-Header-1": "value1",
    "Custom-Header-2": "value2",
    "Host": "",
    "User-Agent": "k6/0.47.0 (",
    "X-Amzn-Trace-Id": "Root=1-65412051-07e38fbb608cf2355393bdd5"
  "json": {
    "name": "Bert"
  "origin": "",
  "url": ""
  group= iter=0 request_id=7ed1feef-76b8-4065-7207-822de4abef81 scenario=default source=http-debug vu=1

So it does seem that k6 itself does what it advertises :smiley:

To try and find the issue you’re experiencing, though, I would need to see a (dumbed-down, anonymized) somewhat more complete version of your script, if that’s possible. Especially one that gives me a good idea of how the body is passed, for instance.

Would you also be able to tell us which version of k6 you’re currently using?

Thank you :wave:

1 Like

Hi @oleiade ,

Thank you for getting back to me. This is the result of the k6 version command → k6 v0.47.0 (commit/5ceb210056, go1.21.2, windows/amd64).

I just took your script and modified it, and indeed, it does as advertised :slight_smile:

The issue is that I worked based on the example script found on the documentation page. As you can see here, the body of the request is not JSON stringified.

Thank you again for your help.

Best regards,

Hey @adrianc137

Glad I could be of some help :bowing_man:

My current assumption is that you have found a solution and you are not experiencing the issue you described initially, is that correct? (checking to avoid misunderstandings on my side).

1 Like

Hi @oleiade ,

Your answer is marked as solution.
Thank you again for your support.


1 Like

I’m glad :bowing_man: