OkHttpClient$Builder.<init>
Code IndexAdd Codota to your IDE (free)

Best code snippets using okhttp3.OkHttpClient$Builder.<init>(Showing top 15 results out of 612)

  • Common ways to obtain OkHttpClient$Builder
private void myMethod () {
OkHttpClient$Builder o =
  • new OkHttpClient.Builder()
  • AI code suggestions by Codota
}
origin: square/okhttp

public CertificatePinning() {
 client = new OkHttpClient.Builder()
   .certificatePinner(
     new CertificatePinner.Builder()
       .add("publicobject.com", "sha256/afwiKY3RxoMmLkuRW1l7QsPZTJPwDS2pdDROQjXw8ig=")
       .build())
   .build();
}
origin: square/okhttp

public ConfigureTimeouts() throws Exception {
 client = new OkHttpClient.Builder()
   .connectTimeout(10, TimeUnit.SECONDS)
   .writeTimeout(10, TimeUnit.SECONDS)
   .readTimeout(30, TimeUnit.SECONDS)
   .build();
}
origin: square/okhttp

private void run() {
 OkHttpClient client = new OkHttpClient.Builder()
   .readTimeout(0,  TimeUnit.MILLISECONDS)
   .build();
 Request request = new Request.Builder()
   .url("ws://echo.websocket.org")
   .build();
 client.newWebSocket(request, this);
 // Trigger shutdown of the dispatcher's executor so this process can exit cleanly.
 client.dispatcher().executorService().shutdown();
}
origin: square/okhttp

public SlackApi(String clientId, String clientSecret, int port) {
 this.httpClient = new OkHttpClient.Builder()
   .build();
 this.moshi = new Moshi.Builder()
   .add(new SlackJsonAdapters())
   .build();
 this.clientId = clientId;
 this.clientSecret = clientSecret;
 this.port = port;
}
origin: square/okhttp

public Builder newBuilder() {
 return new Builder(this);
}
origin: stackoverflow.com

 HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
OkHttpClient client = new OkHttpClient.Builder().addInterceptor(interceptor).build();

Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("https://backend.example.com")
    .client(client)
    .addConverterFactory(GsonConverterFactory.create())
    .build();

return retrofit.create(ApiClient.class);
origin: square/okhttp

public RewriteResponseCacheControl(File cacheDirectory) throws Exception {
 Cache cache = new Cache(cacheDirectory, 1024 * 1024);
 cache.evictAll();
 client = new OkHttpClient.Builder()
   .cache(cache)
   .build();
}
origin: square/retrofit

public static void main(String... args) throws Exception {
 Dispatcher dispatcher = new Dispatcher(Executors.newFixedThreadPool(20));
 dispatcher.setMaxRequests(20);
 dispatcher.setMaxRequestsPerHost(1);
 OkHttpClient okHttpClient = new OkHttpClient.Builder()
   .dispatcher(dispatcher)
   .connectionPool(new ConnectionPool(100, 30, TimeUnit.SECONDS))
   .build();
 Retrofit retrofit = new Retrofit.Builder()
   .baseUrl(HttpUrl.parse("https://example.com/"))
   .addConverterFactory(PageAdapter.FACTORY)
   .client(okHttpClient)
   .build();
 PageService pageService = retrofit.create(PageService.class);
 Crawler crawler = new Crawler(pageService);
 crawler.crawlPage(HttpUrl.parse(args[0]));
}
origin: square/retrofit

 public static void main(String... args) throws IOException {
  HostSelectionInterceptor hostSelectionInterceptor = new HostSelectionInterceptor();

  OkHttpClient okHttpClient = new OkHttpClient.Builder()
    .addInterceptor(hostSelectionInterceptor)
    .build();

  Retrofit retrofit = new Retrofit.Builder()
    .baseUrl("http://www.github.com/")
    .callFactory(okHttpClient)
    .build();

  Pop pop = retrofit.create(Pop.class);

  Response<ResponseBody> response1 = pop.robots().execute();
  System.out.println("Response from: " + response1.raw().request().url());
  System.out.println(response1.body().string());

  hostSelectionInterceptor.setHost("www.pepsi.com");

  Response<ResponseBody> response2 = pop.robots().execute();
  System.out.println("Response from: " + response2.raw().request().url());
  System.out.println(response2.body().string());
 }
}
origin: square/okhttp

private OkHttpClient createClient() {
 OkHttpClient.Builder builder = new OkHttpClient.Builder();
 builder.followSslRedirects(followRedirects);
 if (connectTimeout != DEFAULT_TIMEOUT) {
  builder.connectTimeout(connectTimeout, SECONDS);
 }
 if (readTimeout != DEFAULT_TIMEOUT) {
  builder.readTimeout(readTimeout, SECONDS);
 }
 if (allowInsecure) {
  X509TrustManager trustManager = createInsecureTrustManager();
  SSLSocketFactory sslSocketFactory = createInsecureSslSocketFactory(trustManager);
  builder.sslSocketFactory(sslSocketFactory, trustManager);
  builder.hostnameVerifier(createInsecureHostnameVerifier());
 }
 return builder.build();
}
origin: square/okhttp

public CustomTrust() {
 X509TrustManager trustManager;
 SSLSocketFactory sslSocketFactory;
 try {
  trustManager = trustManagerForCertificates(trustedCertificatesInputStream());
  SSLContext sslContext = SSLContext.getInstance("TLS");
  sslContext.init(null, new TrustManager[] { trustManager }, null);
  sslSocketFactory = sslContext.getSocketFactory();
 } catch (GeneralSecurityException e) {
  throw new RuntimeException(e);
 }
 client = new OkHttpClient.Builder()
   .sslSocketFactory(sslSocketFactory, trustManager)
   .build();
}
origin: square/okhttp

 public static void main(String[] args) throws IOException {
  if (args.length != 2) {
   System.out.println("Usage: Crawler <cache dir> <root>");
   return;
  }

  int threadCount = 20;
  long cacheByteCount = 1024L * 1024L * 100L;

  Cache cache = new Cache(new File(args[0]), cacheByteCount);
  OkHttpClient client = new OkHttpClient.Builder()
    .cache(cache)
    .build();

  Crawler crawler = new Crawler(client);
  crawler.queue.add(HttpUrl.parse(args[1]));
  crawler.parallelDrainQueue(threadCount);
 }
}
origin: square/okhttp

public CacheResponse(File cacheDirectory) throws Exception {
 int cacheSize = 10 * 1024 * 1024; // 10 MiB
 Cache cache = new Cache(cacheDirectory, cacheSize);
 client = new OkHttpClient.Builder()
   .cache(cache)
   .build();
}
origin: square/okhttp

public OkHttpClient() {
 this(new Builder());
}
origin: square/okhttp

public Authenticate() {
 client = new OkHttpClient.Builder()
   .authenticator(new Authenticator() {
    @Override public Request authenticate(Route route, Response response) throws IOException {
     if (response.request().header("Authorization") != null) {
      return null; // Give up, we've already attempted to authenticate.
     }
     System.out.println("Authenticating for response: " + response);
     System.out.println("Challenges: " + response.challenges());
     String credential = Credentials.basic("jesse", "password1");
     return response.request().newBuilder()
       .header("Authorization", credential)
       .build();
    }
   })
   .build();
}
okhttp3OkHttpClient$Builder<init>

Popular methods of OkHttpClient$Builder

  • build
  • readTimeout
    Sets the default read timeout for new connections. A value of 0 means no timeout, otherwise values m
  • connectTimeout
    Sets the default connect timeout for new connections. A value of 0 means no timeout, otherwise value
  • sslSocketFactory
    Sets the socket factory and trust manager used to secure HTTPS connections. If unset, the system def
  • writeTimeout
    Sets the default write timeout for new connections. A value of 0 means no timeout, otherwise values
  • addInterceptor
  • proxy
    Sets the HTTP proxy that will be used by connections created by this client. This takes precedence o
  • followRedirects
    Configure this client to follow redirects. If unset, redirects will be followed.
  • hostnameVerifier
    Sets the verifier used to confirm that response certificates apply to requested hostnames for HTTPS
  • authenticator
    Sets the authenticator used to respond to challenges from origin servers. Use #proxyAuthenticator to
  • connectionPool
    Sets the connection pool used to recycle HTTP and HTTPS connections.If unset, a new connection pool
  • addNetworkInterceptor
  • connectionPool,
  • addNetworkInterceptor,
  • followSslRedirects,
  • proxyAuthenticator,
  • cookieJar,
  • dispatcher,
  • cache,
  • interceptors,
  • retryOnConnectionFailure

Popular classes and methods

  • getSupportFragmentManager (FragmentActivity)
  • runOnUiThread (Activity)
  • scheduleAtFixedRate (ScheduledExecutorService)
    Creates and executes a periodic action that becomes enabled first after the given initial delay, and
  • RandomAccessFile (java.io)
    Saves binary data to the local storage; currently using hex encoding. The string is prefixed with "h
  • SocketException (java.net)
    This SocketException may be thrown during socket creation or setting options, and is the superclass
  • Set (java.util)
    A Set is a data structure which does not allow duplicate elements.
  • Executors (java.util.concurrent)
    Factory and utility methods for Executor, ExecutorService, ScheduledExecutorService, ThreadFactory,
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Collectors (java.util.stream)
  • Reference (javax.naming)

For IntelliJ IDEA and
Android Studio

  • Codota IntelliJ IDEA pluginCodota Android Studio pluginCode IndexSign in
  • EnterpriseFAQAboutContact Us
  • Terms of usePrivacy policyCodeboxFind Usages
Add Codota to your IDE (free)