How to pass form-data than normal raw body in auth rest call

Postman body have form-data . We need to pass same than plane body

sample code :

const authUrl = 'authurl';
const params = {
    headers: {
     'Content-Type': 'x-www-form-urlencoded',
     'Authorization' : 'Basic $encodedeValue'
    },
};

let formData = { type : 'admin'};
let res = http.post(authUrl,formData,params);

but this is failing since data is going as json body / raw body while it should go as form-data .

Please advise.

Hi there,

Your Content-Type is incorrect, it should be application/x-www-form-urlencoded. But in this case you don’t have to specify it, as k6 will set it by default for you.

This is what the request looks like without specifying the Content-Type:

POST /post HTTP/1.1
Host: localhost:8000
User-Agent: k6/0.27.0 (https://k6.io/)
Content-Length: 10
Authorization: Basic $encodedeValue
Content-Type: application/x-www-form-urlencoded

type=admin

@imiric x-www-form-urlencoded is not the same thing as form-data. A form-data request looks like this:

POST /test HTTP/1.1
User-Agent: PostmanRuntime/7.29.2
Host: localhost:8000
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Type: multipart/form-data; boundary=--------------------------242842349955627785108541
Content-Length: 274

----------------------------242842349955627785108541
Content-Disposition: form-data; name="key1"

value1
----------------------------242842349955627785108541
Content-Disposition: form-data; name="key2"

value2
----------------------------242842349955627785108541--

Do you know how to reproduce that in k6?