title: Exit from HttpClient session
body: <p>How to exit from HttpClient session?</p>
  
  <p>I use the following code to login to the application using Apache HttpClient</p>
  
  <pre><code>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&lt;NameValuePair&gt; nameValuePairs = new ArrayList&lt;NameValuePair&gt;(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;
      }
  </code></pre>
  
  <p>like the following :</p>
  
  <pre><code>HttpClient client = new DefaultHttpClient();
  client= httpRequest.loginToHexgen("mayank", "hexgen");
  </code></pre>
  
  <p>here <code>httpRequest</code> is the class where the <code>loginToHexgen</code> method is used.</p>
  
  <p>If I want to login to the system with multiple user with diffrent user name and password how to do this?.</p>
  
  <p>Like for example in the same session I want to logout one user and login using other user.</p>