How do you send form data in a POST request using RestAssured?

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.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top