Is providing tutorial URL allowed?

How do I log out programmatically after providing credentials using HttpClient?

  • I'm using the Apache HttpClient 4.3.4 library in Java to programmatically provide credentials to a URL that requires authentication. This is what I have in my code: public static void clientAuthentication() throws Exception { CredentialsProvider credsProvider = new BasicCredentialsProvider(); credsProvider.setCredentials( AuthScope.ANY, new UsernamePasswordCredentials("username", "password")); CloseableHttpClient httpclient = HttpClients.custom() .setDefaultCredentialsProvider(credsProvider) .build(); try { HttpGet httpget = new HttpGet("Example Domain"); System.out.println("Executing request " + httpget.getRequestLine()); CloseableHttpResponse response = httpclient.execute(httpget); try { System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); for (Header h : response.getAllHeaders()){ System.out.println(h.toString()); } EntityUtils.consume(response.getEntity()); } finally { response.close(); } } finally { httpclient.close(); } } I'm able to successfully authenticate to the URL, as I'm getting a 200 status code. My question is, now that I have "logged in" programmatically, is there a way to "log out" programmatically? This URL doesn't have any "log out" button or anything similar; so I'm wondering how does one log out programmatically. Thanks.

  • Answer:

    HTTP is a stateless protocol, so in that sense, there's no generic way to "log out" from a website. Each website needs its own method. That said, make sure you leave no traces of the response sent back to you, so that your session wouldn't be stolen by other processes on the machine.

Elazar Leibovich at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.