I am very new to this and would like some pointers. i was trying to perform a GET request by passing an ApiToken as a header from postman, and this works perfectly fine.But when i perform the same request from REST assured it throws me a bad request error (400).
Here is my code for Rest Assured.
@Test
public void dump_list(){
RestAssured.baseURI = "https://xxx.xx.xxx.xxx:xx/stm/api";
RestAssured.useRelaxedHTTPSValidation();
String res = given().
header("ApiToken",authenticate()).log().all().
when().
get("/diagnosticsdumps").
then().
extract().response().header("AuthenticationStatus");
}
public String authenticate(){
String token = given().
contentType("application/json").
body("{\"userName\":\"xxxxx\",\"userPwd\":\"xxxxxx*xxxx\"}").
when().
post("/auth/signin").
then().
contentType(ContentType.JSON).statusCode(200).extract().path("data.ApiToken");
return token;
}
The Authentication status i receive is "InvalidSession" (Rest assured)
The log all part of this is in the attached image: request_logs.PNG
The request sent by POSTMAN is:
GET /stm/api/diagnosticsdumps HTTP/1.1
Host: 192.61.237.138:1910
ApiToken: 146306dZhF9DsHdLTLq8hB8E42FE84CFC04AD8A132F18937BF4EB7i7anmt7onmmia717PvtKKfWdl9TDHm3H3k1REEs0ibtOTCxmMdJ5OW1Jd1wuTw8t2mxt9rv7D3
Cache-Control: no-cache
Postman-Token: 041e9331-9ef4-222d-3a23-4779e8ea5a7a
The Authentication status i receive is "Authorized" (Postman)
Except for the Postman-Token, i do not see any difference in the request i have made in postman when compared to Rest-assured, and it works perfectly fine with Postman.