Tabnine Logo
ResponseBody.string
Code IndexAdd Tabnine to your IDE (free)

How to use
string
method
in
okhttp3.ResponseBody

Best Java code snippets using okhttp3.ResponseBody.string (Showing top 20 results out of 4,257)

Refine searchRefine arrow

  • Response.body
canonical example by Tabnine

public void sendGetRequest(String url) throws IOException {
 OkHttpClient client = new OkHttpClient();
 Request request = new Request.Builder().url(url).build();
 try (Response response = client.newCall(request).execute()) {
  String responseBody = response.body().string();
  // ... do something with response
 }
}
origin: square/okhttp

String run(String url) throws IOException {
 Request request = new Request.Builder()
   .url(url)
   .build();
 try (Response response = client.newCall(request).execute()) {
  return response.body().string();
 }
}
origin: square/okhttp

String post(String url, String json) throws IOException {
 RequestBody body = RequestBody.create(JSON, json);
 Request request = new Request.Builder()
   .url(url)
   .post(body)
   .build();
 try (Response response = client.newCall(request).execute()) {
  return response.body().string();
 }
}
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://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: 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: 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: jeasonlzy/okhttp-OkGo

  @Override
  public String convertResponse(Response response) throws Throwable {
    ResponseBody body = response.body();
    if (body == null) return null;
    return body.string();
  }
}
origin: square/okhttp

public void run() throws Exception {
 Map<String, String> requestBody = new LinkedHashMap<>();
 requestBody.put("longUrl", "https://publicobject.com/2014/12/04/html-formatting-javadocs/");
 RequestBody jsonRequestBody = RequestBody.create(
   MEDIA_TYPE_JSON, mapJsonAdapter.toJson(requestBody));
 Request request = new Request.Builder()
   .url("https://www.googleapis.com/urlshortener/v1/url?key=" + GOOGLE_API_KEY)
   .post(jsonRequestBody)
   .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://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: square/okhttp

public void run() throws Exception {
 String postBody = ""
   + "Releases\n"
   + "--------\n"
   + "\n"
   + " * _1.0_ May 6, 2013\n"
   + " * _1.1_ June 15, 2013\n"
   + " * _1.2_ August 11, 2013\n";
 Request request = new Request.Builder()
   .url("https://api.github.com/markdown/raw")
   .post(RequestBody.create(MEDIA_TYPE_MARKDOWN, postBody))
   .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 {
 final PipeBody pipeBody = new PipeBody();
 Request request = new Request.Builder()
   .url("https://api.github.com/markdown/raw")
   .post(pipeBody)
   .build();
 streamPrimesToSinkAsynchronously(pipeBody.sink());
 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://publicobject.com/helloworld.txt")
   .build();
 try (Response response = client.newCall(request).execute()) {
  if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
  Headers responseHeaders = response.headers();
  for (int i = 0; i < responseHeaders.size(); i++) {
   System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
  }
  System.out.println(response.body().string());
 }
}
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);
  Headers responseHeaders = response.headers();
  for (int i = 0; i < responseHeaders.size(); i++) {
   System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
  }
  System.out.println(response.body().string());
 }
}
origin: square/okhttp

public void run() throws Exception {
 RequestBody formBody = new FormBody.Builder()
   .add("search", "Jurassic Park")
   .build();
 Request request = new Request.Builder()
   .url("https://en.wikipedia.org/w/index.php")
   .post(formBody)
   .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

 @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: square/okhttp

public void run() throws Exception {
 RequestBody requestBody = new RequestBody() {
  @Override public MediaType contentType() {
   return MEDIA_TYPE_MARKDOWN;
  }
  @Override public void writeTo(BufferedSink sink) throws IOException {
   sink.writeUtf8("Numbers\n");
   sink.writeUtf8("-------\n");
   for (int i = 2; i <= 997; i++) {
    sink.writeUtf8(String.format(" * %s = %s\n", i, factor(i)));
   }
  }
  private String factor(int n) {
   for (int i = 2; i < n; i++) {
    int x = n / i;
    if (x * i == n) return factor(x) + " × " + i;
   }
   return Integer.toString(n);
  }
 };
 Request request = new Request.Builder()
   .url("https://api.github.com/markdown/raw")
   .post(requestBody)
   .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("http://publicobject.com/helloworld.txt")
   .build();
 String response1Body;
 try (Response response1 = client.newCall(request).execute()) {
  if (!response1.isSuccessful()) throw new IOException("Unexpected code " + response1);
  response1Body = response1.body().string();
  System.out.println("Response 1 response:          " + response1);
  System.out.println("Response 1 cache response:    " + response1.cacheResponse());
  System.out.println("Response 1 network response:  " + response1.networkResponse());
 }
 String response2Body;
 try (Response response2 = client.newCall(request).execute()) {
  if (!response2.isSuccessful()) throw new IOException("Unexpected code " + response2);
  response2Body = response2.body().string();
  System.out.println("Response 2 response:          " + response2);
  System.out.println("Response 2 cache response:    " + response2.cacheResponse());
  System.out.println("Response 2 network response:  " + response2.networkResponse());
 }
 System.out.println("Response 2 equals Response 1? " + response1Body.equals(response2Body));
}
origin: square/okhttp

public void run() throws Exception {
 // Use the imgur image upload API as documented at https://api.imgur.com/endpoints/image
 RequestBody requestBody = new MultipartBody.Builder()
   .setType(MultipartBody.FORM)
   .addFormDataPart("title", "Square Logo")
   .addFormDataPart("image", "logo-square.png",
     RequestBody.create(MEDIA_TYPE_PNG, new File("website/static/logo-square.png")))
   .build();
 Request request = new Request.Builder()
   .header("Authorization", "Client-ID " + IMGUR_CLIENT_ID)
   .url("https://api.imgur.com/3/image")
   .post(requestBody)
   .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

  Response originalResponse = chain.proceed(chain.request());
  return originalResponse.newBuilder()
    .body(new ProgressResponseBody(originalResponse.body(), progressListener))
    .build();
 })
if (!response.isSuccessful()) throw new IOException("Unexpected code " + response);
System.out.println(response.body().string());
okhttp3ResponseBodystring

Javadoc

Returns the response as a string decoded with the charset of the Content-Type header. If that header is either absent or lacks a charset, this will attempt to decode the response body as UTF-8.

Popular methods of ResponseBody

  • byteStream
  • source
  • contentType
  • contentLength
    Returns the number of bytes in that will returned by #bytes, or #byteStream, or -1 if unknown.
  • close
  • bytes
    Returns the response as a byte array.This method loads entire response body into memory. If the resp
  • create
    Returns a new response body that transmits content.
  • charStream
    Returns the response as a character stream decoded with the charset of the Content-Type header. If t
  • charset
  • getClass

Popular in Java

  • Making http requests using okhttp
  • requestLocationUpdates (LocationManager)
  • getResourceAsStream (ClassLoader)
  • getExternalFilesDir (Context)
  • Date (java.sql)
    A class which can consume and produce dates in SQL Date format. Dates are represented in SQL as yyyy
  • Timer (java.util)
    Timers schedule one-shot or recurring TimerTask for execution. Prefer java.util.concurrent.Scheduled
  • ConcurrentHashMap (java.util.concurrent)
    A plug-in replacement for JDK1.5 java.util.concurrent.ConcurrentHashMap. This version is based on or
  • Executor (java.util.concurrent)
    An object that executes submitted Runnable tasks. This interface provides a way of decoupling task s
  • Pattern (java.util.regex)
    Patterns are compiled regular expressions. In many cases, convenience methods such as String#matches
  • Location (org.springframework.beans.factory.parsing)
    Class that models an arbitrary location in a Resource.Typically used to track the location of proble
  • Best plugins for Eclipse
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

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