How do you set the content type of a request in RestAssured?

How do you set the content type of a request in RestAssured?

A) contentType()
B) setType()
C) withContent()
D) addType()

Answer:

A) contentType()

Explanation:

The contentType() method in RestAssured is used to set the content type of the request, such as JSON, XML, or form data. This ensures that the server processes the request correctly.

For example:


import static io.restassured.RestAssured.*;

given().
    contentType("application/json").
    body("{\"key\":\"value\"}").
    when().
    post("/api/resource").
    then().
    statusCode(201);

In this example, the contentType() method sets the content type of the request to “application/json”.

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