Receiving a bad request error(400) when using REST Assured, but works fine with Postman

3,537 views
Skip to first unread message

Pramod S

unread,
Jan 18, 2018, 9:54:10 AM1/18/18
to REST assured
Hi, 
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.
request_logs.PNG

Johan Haleby

unread,
Jan 19, 2018, 2:22:45 AM1/19/18
to rest-a...@googlegroups.com
Try to avoid adding charset automatically, sometimes algorithms are sensitive to that. See docs here.

--
You received this message because you are subscribed to the Google Groups "REST assured" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rest-assured+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages