The question I have is that -- Is this the best way to get the response in case of auto-redirects?
I was facing a problem while trying to login in a site, to which I found a solution but still I have some doubt as follows:
I passed userid & password to a login page and submitted request. As a result, I should have got an expected home page of the site. But I was getting redirected back to the login page.
After struggling with this problem (using Fiddler) for a while, I could finally find the solution. The solution being capturing the SET-COOKIE header from the first response and setting it as cookie before sending the request back in a series of auto-redirects.
This site was deployed on a WS portal and I was accessing the Portal login page.
Please note the string array to hold the SET-COOKIE values in an array and setting it back in Web Conversation in a particular format to get the correct response back from portal server. The cookie contains jsessionid, ltpatoken & login info.
The question I have is that -- Is this the best way to get the response?
Please help me conclude on this problem.
Thanks,
kriju
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Login processes are of course not stateless. Still in most cases it's not necessary to set the cookie information explicitly. A simple autoredirect should do if the login uses e.g. POST parameters.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi,
The question I have is that -- Is this the best way to get the response in case of auto-redirects?
I was facing a problem while trying to login in a site, to which I found a solution but still I have some doubt as follows:
I passed userid & password to a login page and submitted request. As a result, I should have got an expected home page of the site. But I was getting redirected back to the login page.
After struggling with this problem (using Fiddler) for a while, I could finally find the solution. The solution being capturing the SET-COOKIE header from the first response and setting it as cookie before sending the request back in a series of auto-redirects.
This site was deployed on a WS portal and I was accessing the Portal login page.
Following code works fine:
//Start
resp = wc.getResponse( "http://xyz.portal.com/orgaccess" );
String referer = "";
while(resp.getHeaderField("LOCATION") !=null){
referer = resp.getHeaderField("LOCATION");
resp = wc.getResponse( resp.getHeaderField("LOCATION"));
}
WebForm form = resp.getForms()[0];
req = form.getRequest(form.getSubmitButtons()[0]);
req.setParameter(resp.getElementWithID("userID").getName(),"XYZ ABC");
req.setParameter(resp.getElementWithID("password").getName(),"testpwd");
resp = wc.getResponse(req);
String [] headerFieldNames = resp.getHeaderFields("SET-COOKIE");
String cookie = "";
cookie = headerFieldNames[2] + "; " + headerFieldNames[4] + "; " + headerFieldNames[1];
wc.setHeaderField("Cookie:",cookie);
while(resp.getHeaderField("LOCATION") !=null){
resp = wc.getResponse( resp.getHeaderField("LOCATION"));
}
assertTrue(resp.getTitle().indexOf("Welcome") >= 0);
//End
Please note the string array to hold the SET-COOKIE values in an array and setting it back in Web Conversation in a particular format to get the correct response back from portal server. The cookie contains jsessionid, ltpatoken & login info.
The question I have is that -- Is this the best way to get the response?
Please help me conclude on this problem.
Thanks,
kriju
Login processes are of course not stateless. Still in most cases it's not necessary to set the cookie information explicitly. A simple autoredirect should do if the login uses e.g. POST parameters.