Tabnine Logo
Response.isSuccessful
Code IndexAdd Tabnine to your IDE (free)

How to use
isSuccessful
method
in
okhttp3.Response

Best Java code snippets using okhttp3.Response.isSuccessful (Showing top 20 results out of 2,160)

Refine searchRefine arrow

  • Response.body
  • Request.Builder.<init>
  • OkHttpClient.newCall
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/helloworld.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://api.github.com/repos/square/okhttp/issues")
   .header("User-Agent", "OkHttp Headers.java")
   .addHeader("Accept", "application/json; q=0.5")
   .addHeader("Accept", "application/vnd.github.v3+json")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println("Server: " + response.header("Server"));
  System.out.println("Date: " + response.header("Date"));
  System.out.println("Vary: " + response.headers("Vary"));
 }
}
origin: square/okhttp

 @Override public void onResponse(Call call, Response response) throws IOException {
  try (ResponseBody responseBody = response.body()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
   Headers responseHeaders = response.headers();
   for (int i = 0, size = responseHeaders.size(); i < size; i++) {
    System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
   }
   System.out.println(responseBody.string());
  }
 }
});
origin: stackoverflow.com

Subscription subscription =   Observable.create(new Observable.OnSubscribe<Response>() {
   OkHttpClient client = new OkHttpClient();
    @Override
    public void call(Subscriber<? super Response> subscriber) {
     try {
      Response response = client.newCall(new Request.Builder().url("your url").build()).execute();
      subscriber.onNext(response);
      subscriber.onCompleted();
      if (!response.isSuccessful()) subscriber.onError(new Exception("error"));
     } catch (IOException e) {
      subscriber.onError(e);
     }
    }
   })
     .subscribeOn(Schedulers.io())
     .observeOn(AndroidSchedulers.mainThread())
     .subscribe(new Subscriber<Response>() {
      @Override
      public void onCompleted() {
      }
      @Override
      public void onError(Throwable e) {
      }
      @Override
      public void onNext(Response response) {
      }
     });
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/secrets/hellosecret.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}
origin: stackoverflow.com

 post("http://www.roundsapp.com/post", json, new Callback() {
 @Override
 public void onFailure(Request request, Throwable throwable) {
   // Something went wrong
 }

 @Override public void onResponse(Response response) throws IOException {
  if (response.isSuccessful()) {
    String responseStr = response.body().string();
    // Do what you want to do with the response.
  } else {
    // Request not successful
  }
 }
});
origin: apache/flink

private void validateApiKey() {
  Request r = new Request.Builder().url(validateUrl).get().build();
  try (Response response = client.newCall(r).execute()) {
    if (!response.isSuccessful()) {
      throw new IllegalArgumentException(
        String.format("API key: %s is invalid", apiKey));
    }
  } catch (IOException e) {
    throw new IllegalStateException("Failed contacting Datadog to validate API key", e);
  }
}
origin: stackoverflow.com

    .build();
Request request = new Request.Builder()
    .url(serverURL)
    .post(requestBody)
    if (!response.isSuccessful()) {
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("http://publicobject.com/secrets/hellosecret.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}
origin: stackoverflow.com

post("http://www.roundsapp.com/post", "", new Callback() {
   @Override
   public void onFailure(Call call, IOException e) {
     // Something went wrong
   }
   @Override
   public void onResponse(Call call, Response response) throws IOException {
     if (response.isSuccessful()) {
       String responseStr = response.body().string();
       // Do what you want to do with the response.
     } else {
       // Request not successful
     }
   }
 });
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/robots.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  for (Certificate certificate : response.handshake().peerCertificates()) {
   System.out.println(CertificatePinner.pin(certificate));
  }
 }
}
origin: square/okhttp

public void run() throws Exception {
 File file = new File("README.md");
 Request request = new Request.Builder()
   .url("https://api.github.com/markdown/raw")
   .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, file))
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.body().string());
 }
}
origin: bumptech/glide

@Override
public void onResponse(@NonNull Call call, @NonNull Response response) {
 responseBody = response.body();
 if (response.isSuccessful()) {
  long contentLength = Preconditions.checkNotNull(responseBody).contentLength();
  stream = ContentLengthInputStream.obtain(responseBody.byteStream(), contentLength);
  callback.onDataReady(stream);
 } else {
  callback.onLoadFailed(new HttpException(response.message(), response.code()));
 }
}
origin: square/okhttp

public void run() throws Exception {
 for (int i = 0; i < 5; i++) {
  System.out.println("    Request: " + i);
  Request request = new Request.Builder()
    .url("https://api.github.com/search/repositories?q=http")
    .build();
  OkHttpClient clientForCall;
  if (i == 2) {
   // Force this request's response to be written to the cache. This way, subsequent responses
   // can be read from the cache.
   System.out.println("Force cache: true");
   clientForCall = client.newBuilder()
     .addNetworkInterceptor(REWRITE_CACHE_CONTROL_INTERCEPTOR)
     .build();
  } else {
   System.out.println("Force cache: false");
   clientForCall = client;
  }
  try (Response response = clientForCall.newCall(request).execute()) {
   if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
   System.out.println("    Network: " + (response.networkResponse() != null));
   System.out.println();
  }
 }
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://api.github.com/gists/c2a7c39532239ff261be")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  Gist gist = gistJsonAdapter.fromJson(response.body().source());
  for (Map.Entry<String, GistFile> entry : gist.files.entrySet()) {
   System.out.println(entry.getKey());
   System.out.println(entry.getValue().content);
  }
 }
}
origin: runelite/runelite

  @Override
  public void onResponse(Call call, Response response) throws IOException
  {
    try (ResponseBody responseBody = response.body())
    {
      if (!response.isSuccessful())
      {
        log.warn("Failed to download image " + item.getAvatar());
        return;
      }
      BufferedImage icon;
      synchronized (ImageIO.class)
      {
        icon = ImageIO.read(responseBody.byteStream());
      }
      avatar.setIcon(new ImageIcon(icon));
    }
  }
});
origin: openzipkin/brave

@Test public void currentSpanVisibleToOtherFilters() throws Exception {
 delegate = userFilter;
 String path = "/foo";
 Request request = new Request.Builder().url(url(path))
   .header(EXTRA_KEY, "abcdefg").build();
 try (Response response = client.newCall(request).execute()) {
  assertThat(response.isSuccessful()).isTrue();
  assertThat(response.header(EXTRA_KEY))
    .isEqualTo("abcdefg");
 }
 takeSpan();
}
origin: square/okhttp

public void run() throws Exception {
 Request request = new Request.Builder()
   .url("https://publicobject.com/helloworld.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  System.out.println(response.handshake().cipherSuite());
  System.out.println(response.body().string());
 }
}
origin: openzipkin/brave

/**
 * The /extra endpoint should copy the key {@link #EXTRA_KEY} to the response body using
 * {@link ExtraFieldPropagation#get(String)}.
 */
void readsExtra(Request.Builder builder) throws Exception {
 Request request = builder.url(url("/extra"))
   // this is the pre-configured key we can pass through
   .header(EXTRA_KEY, "joey").build();
 Response response = get(request);
 assertThat(response.isSuccessful()).isTrue();
 // if we can read the response header, the server must have been able to copy it
 assertThat(response.body().source().readUtf8())
   .isEqualTo("joey");
}
origin: openzipkin/brave

@Test public void traceContextVisibleToOtherFilters() throws Exception {
 delegate = traceContextFilter;
 String path = "/foo";
 Request request = new Request.Builder().url(url(path))
   .header(EXTRA_KEY, "abcdefg").build();
 try (Response response = client.newCall(request).execute()) {
  assertThat(response.isSuccessful()).isTrue();
  assertThat(response.header(EXTRA_KEY))
    .isEqualTo("abcdefg");
 }
 takeSpan();
}
okhttp3ResponseisSuccessful

Javadoc

Returns true if the code is in [200..300), which means the request was successfully received, understood, and accepted.

Popular methods of Response

  • body
    Returns a non-null value if this response was passed to Callback#onResponse or returned from Call#ex
  • code
    Returns the HTTP status code.
  • headers
  • request
    The wire-level request that initiated this HTTP response. This is not necessarily the same request i
  • newBuilder
  • message
    Returns the HTTP status message.
  • header
  • close
    Closes the response body. Equivalent to body().close().It is an error to close a response that is no
  • protocol
    Returns the HTTP protocol, such as Protocol#HTTP_1_1 or Protocol#HTTP_1_0.
  • networkResponse
    Returns the raw response received from the network. Will be null if this response didn't use the net
  • cacheResponse
    Returns the raw response received from the cache. Will be null if this response didn't use the cache
  • toString
  • cacheResponse,
  • toString,
  • handshake,
  • priorResponse,
  • sentRequestAtMillis,
  • cacheControl,
  • challenges,
  • peekBody,
  • receivedResponseAtMillis

Popular in Java

  • Reactive rest calls using spring rest template
  • requestLocationUpdates (LocationManager)
  • getApplicationContext (Context)
  • addToBackStack (FragmentTransaction)
  • Window (java.awt)
    A Window object is a top-level window with no borders and no menubar. The default layout for a windo
  • FileNotFoundException (java.io)
    Thrown when a file specified by a program cannot be found.
  • ConnectException (java.net)
    A ConnectException is thrown if a connection cannot be established to a remote host on a specific po
  • ByteBuffer (java.nio)
    A buffer for bytes. A byte buffer can be created in either one of the following ways: * #allocate
  • Charset (java.nio.charset)
    A charset is a named mapping between Unicode characters and byte sequences. Every Charset can decode
  • Options (org.apache.commons.cli)
    Main entry-point into the library. Options represents a collection of Option objects, which describ
  • Sublime Text for Python
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimAtomGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyStudentsTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now