1

I am trying to hit API using Rest assured which is a POST request with form param client id, user and password. and multiple header .

I am getting 415, unsupportted media type error. My code is:

Response res =    
given().
        .header("Accept", "application/json")

        .header("Content-Type", "application/x-www-form-urlencoded")
        .header("channel","")
        .formParam("grant_type", "password")
        .formParam("client_id", "")
        .formParam("secret", "")
        .formParam("userId", "")
        .formParam("password","").

        when()
            .post("/apiname");
            System.out.println(res.body().asString());

Return type is json.

Same thing is working on PostMan. Please help in this.

itin
  • 430
  • 3
  • 9
  • 20

1 Answers1

0

There is property in request specification for configuring the content type. Not sure that if we have to explicitly define it but i'm using the below given syntax.

given()
            .header("Accept", "application/json")
            .contentType("application/x-www-form-urlencoded")
            .header("channel","")
            .formParam("grant_type", "password")
            .formParam("client_id", "")
            .formParam("secret", "")
            .formParam("userId", "")
            .formParam("password","").
                    when()
            .post("/apiname");
rohit.jaryal
  • 320
  • 1
  • 8