Getting 500 using rest-assured but getting 200 in Postman

114 Views Asked by At

In postman, I input URL, POST method, Header (key - x-api-key and value), in Body (listId and value) and by sending the request getting 200 success response.

postman response

But using maven project, Java language and rest-assured, I am getting -

Response status code: 500 & Response body: The page cannot be displayed because an internal server error has occurred.

Here is my code -

import org.testng.Assert;
import org.testng.annotations.Test;
import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.restassured.http.Method;
import io.restassured.response.Response;
import io.restassured.response.ResponseBody;
import io.restassured.specification.RequestSpecification;

import static io.restassured.RestAssured.given;

public class TC001_CacheStatus {
    @Test
    public void CacheStatusCheck() throws IOException {
     
        // Set base URI of the API
        String baseUrl = "https://url.here";

        // Define headers
        String apiKey = "X-ApiKey";
        String apiValue = "value_here";

        // Define form data
        String formDataKey = "listId";
        String listId = "65cd9b8f";

        // Send POST request with headers and form data
        Response response =   RestAssured.given()
                                    .baseUri(baseUrl)
                                    .header("x-api-key", apiKey) 
                                    .multiPart("listId", listId)
                                    .contentType("multipart/form-data")
                                    .post("/endpoint")
                                    .andReturn();


        // Print response
        System.out.println("Response status code: " + response.getStatusCode());
        System.out.println("Response body: " + response.getBody().asString());

    }
}

How can I solve this? Please help.

1

There are 1 best solutions below

1
Anna On

Try response.then().log().ifValidationFails() to check if post-query is right.