I try to call a call to rest, remaining confident. My API accepts "application/json" as a content type, and I need to set it in a call. I set the content type as below.
Option 1
Response resp1 = given().log().all().header("Content-Type","application/json") .body(inputPayLoad).when().post(addUserUrl); System.out.println("Status code - " +resp1.getStatusCode());
Option 2
Response resp1 = given().log().all().contentType("application/json") .body(inputPayLoad).when().post(addUserUrl);
The answer I get is "415" (indicates "Unsupported media type").
I tried using the same api using simple Java code and it works. For some mysterious reason, I don't get it through RA.
HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(addUserUrl); StringEntity input = new StringEntity(inputPayLoad); input.setContentType("application/json"); post.setEntity(input); HttpResponse response = client.execute(post); System.out.println(response.getEntity().getContent());
java rest-assured
Techookie
source share