How to parse form-data format to K6

Hello I just wanna ask about to parse form-data format that contains real_url in body API.

Can somebody help me?

i tried something like this

var body = “------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name="real_url"\r\n\r\nhttps://blblabla.dummylink.com\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW–”;

but it just invalid format, and the POST method not doing well because of it, then I got response ‘400’ from the server.

Hey, sorry for the very late reply - this one must have slipped our radar! I do think this is a good question that maybe others might have as well, though, so @simme and I answered this live during our k6 Office Hours.

To summarize what we said, though, we think there might be something wrong with the way you’re formulating the body of the request, which is why you’re getting an HTTP 400 back. A good way to troubleshoot this would be to try sending this request in something like Postman to verify whether the format is correct. If you do try this and it works in Postman but not in k6, please post what was sent in both so that we can troubleshoot further. Hope that helps!

2 Likes

helloo @nicole it has been solved anyway.
I found the solution, is to use HAR converter to K6, and it perfectly works wuhu!
Thankyouuu for ur attention nicole, have a great day!

This is the way it looks like in Postman

Thanks for the update! Glad you got it working, and that the HAR converter worked for you! :slight_smile:

yap finally I simulate it with the browser and export the HAR then convert it~

1 Like