How to log out of an HttpClient session?
I use the following code to enter the application using Apache HttpClient
public HttpClient loginToHexgen(String username, String password) { HttpClient client = new DefaultHttpClient(); // send post url to login to hexgen HttpPost post = new HttpPost("http://localhost:8080/j_spring_security_check"); try { // set the user name and 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; }
as below:
HttpClient client = new DefaultHttpClient(); client= httpRequest.loginToHexgen("mayank", "hexgen");
here httpRequest is a class that uses the loginToHexgen method.
If I want to log in with multiple users with different usernames and passwords, how do I do this?
As in the same session, I want to log out of one user and log in using another user.
source share