I'm using testcafe API to make an API request. I need to use form data as the body of the post request. (The request looks something similar to curl -F username=xxx -F password=xxx https://xxxxx/api/login)
const response = await t.request.post({
url: "https://xxxxx/api/login",
body: {'username': 'xxx', 'password':'xxxx'},
headers: { "content-type": "multipart/form-data" }
});
console.log(JSON.stringify(response));
}
This question may look similar to my requirement, but I don't need a 'Form' option. I just want to make a post request with form data.
You need to use
form-datalibrary in your testCafe code.testCafe code
test.js
Server code
Demo local server.js by 'express'
result
Left: server, Right: testCafe
Call by Postman