java - Exit from HttpClient session -
how exit httpclient session?
i use following code login application using apache httpclient
public httpclient logintohexgen(string username, string password) { httpclient client = new defaulthttpclient(); // send post url login hexgen httppost post = new httppost("http://localhost:8080/j_spring_security_check"); try { // set user name , password list<namevaluepair> namevaluepairs = new arraylist<namevaluepair>(1); namevaluepairs.add(new basicnamevaluepair("j_username", username)); namevaluepairs.add(new basicnamevaluepair("j_password", password)); post.setentity(new urlencodedformentity(namevaluepairs)); httpresponse response = client.execute(post); httpentity entity = response.getentity(); if (entity != null) { post.abort(); } } catch (ioexception e) { e.printstacktrace(); } return client; }
like following :
httpclient client = new defaulthttpclient(); client= httprequest.logintohexgen("mayank", "hexgen");
here httprequest
class logintohexgen
method used.
if want login system multiple user diffrent user name , password how this?.
like example in same session want logout 1 user , login using other user.
you may use workaround – send request new user new cookiestore.
// create local instance of cookie store cookiestore = new basiccookiestore(); // set store httpclient.setcookiestore(cookiestore);
server open new session new user. please note old session not closed. not recommend use way.
the session management performed on server side – can not on client side. recommend in end of test should call server url invalidate session on server side. (generally applications use form authentication have logout functionality , need use it)
Comments
Post a Comment