Advertisement
Guest User

Untitled

a guest
Jul 13th, 2016
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. public void proxy_test_auth2() throws IOException
  2. {
  3.  
  4. String ntUsername = "andrshpa";
  5. String ntPassword = "12wedfik";
  6. String localMachineName = System.getenv("COMPUTERNAME");
  7. String domainName = System.getenv("USERDOMAIN");
  8. String proxyHost = "37.143.11.127";
  9. int proxyPort = 65233;
  10.  
  11. NTCredentials ntCreds = new NTCredentials(ntUsername, ntPassword, localMachineName, domainName);
  12.  
  13. CredentialsProvider credsProvider = new BasicCredentialsProvider();
  14. credsProvider.setCredentials( new AuthScope(proxyHost,proxyPort), ntCreds );
  15.  
  16. CloseableHttpClient httpclient = HttpClients.custom()
  17. .setDefaultCredentialsProvider(credsProvider)
  18. .setProxy(new HttpHost(proxyHost, proxyPort))
  19. .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())
  20. .build();
  21.  
  22. try {
  23.  
  24. HttpGet httpget = new HttpGet("http://control456.ru/sample/save_post_get.php");
  25.  
  26. System.out.println("Executing request " + httpget.getRequestLine());
  27.  
  28.  
  29.  
  30. // Pass local context as a parameter
  31. CloseableHttpResponse response = httpclient.execute(httpget);
  32.  
  33.  
  34. System.out.println(response.getStatusLine().toString());
  35.  
  36.  
  37. try {
  38.  
  39. System.out.println("----------------------------------------");
  40. System.out.println(response.getStatusLine());
  41.  
  42. } finally {
  43. response.close();
  44. }
  45.  
  46. } finally {
  47. httpclient.close();
  48. }
  49.  
  50. HTTP/1.0 407 Proxy Authentication Required
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement