K6 adding the header Content-Type: application/x-www-form-urlencoded while doing a post?

Hi I am having a small scenario.
I am trying to issue a k6 post request . However the k6 add this header Content-Type: application/x-www-form-urlencoded . I dont want to add this add header in my request and i want to have this “content-type”: “application/json”. please let me know how to achieve this

import http from ‘k6/http’;

export const payload = JSON.stringify({
firstField: ‘Sample value’
});

export const headers = {
headers: {
“content-type”: “application/json”
}
};

export const options = {
discardResponseBodies: false,
scenarios: {
defaultOperationPriority: {
executor: ‘constant-vus’,
exec: ‘defaultOperationSubPriority’,
startTime: ‘0s’,
vus: 1,
duration: ‘3s’,
},
configuredOperationPriority: {
executor: ‘constant-vus’,
exec: ‘configuredOperationSubPriority’,
startTime: ‘1s’,
vus: 1,
duration: ‘3s’,
},
},
};

export function defaultOperationSubPriority() {
http.post(‘http://10.96.59.144:80/SccTestService/v1/requestMirror’, headers);
}

export function configuredOperationSubPriority() {
// http.get(‘http://10.96.59.144:80/SccTestService/v1/id’);
}

the response output

group= iter=363 request_id=9fc32fb1-8de7-4c2e-50f3-ab014f127e9f scenario=defaultOperationPriority source=http-debug vu=1
INFO[0001] Request:
POST /SccTestService/v1/requestMirror HTTP/1.1
Host: 10.96.59.144:80
Content-Length: 50
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip

please help

i founded out it was wrong
http.post(‘http://10.96.59.144:80/SccTestService/v1/requestMirror’, headers);

http.post(‘http://10.96.59.144:80/SccTestService/v1/requestMirror’, payload, headers);

1 Like