I am using Rest Assured for testing API
WHEN I post a request for authentication, the error occurs to say that: "java.lang.IllegalArgumentException: Cannot serialize because cannot determine how to serialize content-type application/x-www-form-urlencoded;charset=UTF-8"
Here is my test method
@Test
public void authenticate()
{
AuthenDto authenDto = new AuthenDto("username","password","false","Login");
given()
.contentType("application/x-www-form-urlencoded;charset=UTF-8")
.accept("application/json, text/plain, */*")
.body(authenDto)
.when()
.post("ENDPOINT")
.then()
.statusCode(200);
}
I faced the same problem and resolved the issue by using formParams in place of body. Code snippet below:
given().
contentType("application/x-www-form-urlencoded").
accept("*/*").
formParams(bodyContent).relaxedHTTPSValidation(). //bodyContent=hashMap variable
when().
post("/register").
then().
extract().
response();
Credit to following post: https://github.com/rest-assured/rest-assured/issues/841
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With