Post Request with API Key and Authorization

40 views
Skip to first unread message

Kazim Nihat Tekiner

unread,
Nov 10, 2021, 5:02:26 AM11/10/21
to REST assured
I'm new to rest assured. I need to send API Key and Autherization while making post request. When I do it with Postman(in headers), I can get a response, but when I do it with rest assured, I get "status": 415. I'm writing my code below, I wonder what I wrote wrong? I would be glad if you can help. 

RequestSpecification spec = new RequestSpecBuilder().setBaseUri("url").build();

spec.pathParams("p1","v1","p2","get-ad");


Response responseAndroid = given().headers("x-api-key","xx","authorization", "aa").accept(ContentType.JSON).spec(spec).body(pojoGetAdvertisementAndroid).
post("/{p1}/{p2}");

Raj Chahal

unread,
Nov 10, 2021, 10:55:32 PM11/10/21
to REST assured
Hi Kazim,
415 means that server is not able to accept the payload format.
So try adding header with content-type as json.

Emre Baş

unread,
Nov 11, 2021, 4:05:21 AM11/11/21
to REST assured
Hi Kazim,
Can you log your request/response with filter? Was it the same as with the request on Postman?

Kazim Nihat Tekiner

unread,
Nov 15, 2021, 3:35:24 AM11/15/21
to REST assured
Hello, i found the problem. Problem is  accept(ContentType.JSON), i used contentType(ContentType.JSON) and problem solved. Thank you for your answers.

11 Kasım 2021 Perşembe tarihinde saat 12:05:21 UTC+3 itibarıyla bas4...@gmail.com şunları yazdı:
Reply all
Reply to author
Forward
0 new messages