Anu
Anu

Reputation: 11

Rest assured - Expected content-type "JSON" doesn't match actual content-type "text/html"

I am getting below in response when i am expecting json response -

<!DOCTYPE HTML><html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">

whole page content

</html> 

I am using rest assured to test the service -

Response response = given().accept(ContentType.JSON).when().get("link to my rest service");

even tried -> header("Content-Type", "application/json") and contentType(ContentType.JSON) but getting same result

Here is the rest service code -

@GET
@Path("/getUser")
@Produces(MediaType.APPLICATION_JSON)
public Response getUser() {
    User user = new User();
    user.setfName("Abc");
    user.setlName("Ben");
    user.setRacf("A1234");
    user.setEmpId("abcd12");
    return 
Response.ok(user).type(MediaType.APPLICATION_JSON_TYPE).build();

Upvotes: 1

Views: 4142

Answers (1)

StackThao
StackThao

Reputation: 81

The issue something your mistake, when are your sending get method http then the error be displayed. I change get -> post . This should work

Upvotes: 1

Related Questions