Advertisement
Guest User

Untitled

a guest
Apr 19th, 2014
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. RequestConfig requestConfig = RequestConfig.custom()
  2. .setTargetPreferredAuthSchemes(Arrays.asList(AuthSchemes.BASIC))
  3. .setProxyPreferredAuthSchemes(Arrays.asList(AuthSchemes.NTLM, AuthSchemes.DIGEST))
  4. .build();
  5.  
  6. CloseableHttpClient httpclient = HttpClients.createDefault();
  7. try {
  8. HttpClientContext localContext = HttpClientContext.create();
  9. HttpGet httpget = new HttpGet("http://localhost/");
  10. CloseableHttpResponse response = httpclient.execute(httpget, localContext);
  11. try {
  12. System.out.println(response.getStatusLine());
  13. EntityUtils.consume(response.getEntity());
  14. AuthState targetAuthState = localContext.getTargetAuthState();
  15. if (targetAuthState.getAuthScheme() != null) {
  16. System.out.println("Target auth scheme: " +
  17. targetAuthState.getAuthScheme().getSchemeName());
  18. }
  19. AuthState proxyAuthState = localContext.getProxyAuthState();
  20. if (proxyAuthState.getAuthScheme() != null) {
  21. System.out.println("Proxy auth scheme: " +
  22. proxyAuthState.getAuthScheme().getSchemeName());
  23. }
  24.  
  25. } finally {
  26. response.close();
  27. }
  28. } finally {
  29. httpclient.close();
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement