Skip to content

Instantly share code, notes, and snippets.

@ogregoire
Last active March 28, 2017 09:08
Show Gist options
  • Save ogregoire/98db7d5eefdeb83604bb622747b23b61 to your computer and use it in GitHub Desktop.
Save ogregoire/98db7d5eefdeb83604bb622747b23b61 to your computer and use it in GitHub Desktop.
OkHttpExample
OkHttpClient client = new OkHttpClient.Builder()
// Logging
.addInterceptor(new HttpLoggingInterceptor(System.err::println).setLevel(HttpLoggingInterceptor.Level.BODY))
// Timeout
.connectTimeout(60, TimeUnit.SECONDS)
.writeTimeout(60, TimeUnit.SECONDS)
.readTimeout(60, TimeUnit.SECONDS)
// Proxy
.proxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort))
.proxyAuthenticator(($, response) -> response.request().newBuilder()
.header("Proxy-Authorization", Credentials.basic(proxyUser, proxyPassword))
.build())
.build();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment