How do you send form data in a POST request using RestAssured?
A) formParam()
B) param()
C) formData()
D) withForm()
Answer:
A) formParam()
Explanation:
The formParam()
method in RestAssured is used to send form data in an HTTP POST request. This method is useful for submitting data in form-encoded format.
For example:
import static io.restassured.RestAssured.*;
given().
contentType("application/x-www-form-urlencoded").
formParam("key", "value").
when().
post("/api/resource").
then().
statusCode(200);
In this example, the formParam()
method sends form data with the key “key” and value “value” in the POST request.