Guest User

Untitled

a guest
Aug 22nd, 2018
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. int proxyPort = 8080;
  2. String proxyHost = "proxyHost";
  3. final String username = "username";
  4. final String password = "password";
  5.  
  6. Authenticator proxyAuthenticator = new Authenticator() {
  7. @Override public Request authenticate(Route route, Response response) throws IOException {
  8. String credential = Credentials.basic(username, password);
  9. return response.request().newBuilder()
  10. .header("Proxy-Authorization", credential)
  11. .build();
  12. }
  13. };
  14.  
  15. OkHttpClient client = new OkHttpClient.Builder()
  16. .connectTimeout(60, TimeUnit.SECONDS)
  17. .writeTimeout(60, TimeUnit.SECONDS)
  18. .readTimeout(60, TimeUnit.SECONDS)
  19. .proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort)))
  20. .proxyAuthenticator(proxyAuthenticator)
  21. .build();
Add Comment
Please, Sign In to add comment