Params.responseType = 'text' not working

Hi!

Currently I am setting the options of k6 to discard response bodies:

export const options = {
  discardResponseBodies: true,
  scenarios: {},
};

But I have a specific endpoint that I need the body, I’m trying to use the Params.responseType = ‘text’, but I keep getting null.


let scenarios = {
  createUser: {
    executor: 'per-vu-iterations',
    exec: 'createUser',
    vus: 2,
    iterations: 1,
    startTime: '1s'
  }
};

export const options = {
  discardResponseBodies: true,
  scenarios: {},
};

if (__ENV.scenario) {
  options.scenarios[__ENV.scenario] = scenarios[__ENV.scenario];
} else {
  options.scenarios = scenarios;
}


export function createUser() {
  let body = {
    'cpf': '1111111',
  }
  const response = http.post('https://...', JSON.stringify(body), {headers: {
    'Content-Type': 'application/json',
  }}, {
    responseType: "text",
  });
  console.log('test', response.status, response.body)

}

Hi @marianafiori,
you’re setting 4 arguments for your Post call. As defined by post( url, [body], [params] ) documentation the Params object is the 3rd argument. responsesType must be part of the Params object.

The correct invocation is:

const response = http.post('https://...', JSON.stringify(body), {
  headers: {
    'Content-Type': 'application/json',
  },
  responseType: "text",
});

Let me know if it helps.