Hi,
I am new to Rest Assured and got stuck in calling a REST API. It requires two authentication before a call.
1. Basic Authentication
2. Form Authentication
Sample Code :
RestAssured.basePath = "/abc";
// Basic Authentication
RestAssured.authentication = RestAssured.basic("userName", "password");
// Form authentication which returns session id.
String sessionId = RestAssured.given().auth().form("userName", "password").
contentType("application/x-www-form-urlencoded").
when().get("/Login.action").getSessionId();
// Sets session id for all requests.
RestAssured.sessionId = sessionId;
// Calling REST API
RestAssured.given().sessionId(sessionId).contentType("application/json").body(myJson).when().post("/api/something.action").then().log().all();
Now both the authentication are working fine as I have asserted with the help of status code which is 200 and generated the session id. But still the call to API is redirecting to login page. Logs generated can be found below -
HTTP/1.1 302 Moved Temporarily
Date: Wed, 17 Aug 2016 12:44:56 GMT
Server: Apache-Coyote/1.1
X-Powered-By: Servlet/3.0; JBossAS-6
Content-Length: 0
Cache-Control: public
Connection: close
Content-Type: text/plain; charset=UTF-8
Can someone please help me ?? What's wrong with the above code ?
Thanks,
Akash