Tabnine Logo
Request$Builder.post
Code IndexAdd Tabnine to your IDE (free)

How to use
post
method
in
okhttp3.Request$Builder

Best Java code snippets using okhttp3.Request$Builder.post (Showing top 20 results out of 2,547)

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 {
 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: 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: yu199195/Raincat

public String post(String url,String json) throws IOException {
  OkHttpClient client = new OkHttpClient();
  RequestBody body = RequestBody.create(JSON, json);
  Request request = new Request.Builder()
      .url(url)
      .post(body)
      .build();
  Response response = client.newCall(request).execute();
  return response.body().string();
}
origin: SonarSource/sonarqube

private Response followPostRedirect(Response response, PostRequest postRequest) {
 String location = response.header("Location");
 if (location == null) {
  throw new IllegalStateException(format("Missing HTTP header 'Location' in redirect of %s", response.request().url()));
 }
 HttpUrl url = response.request().url().resolve(location);
 // Don't follow redirects to unsupported protocols.
 if (url == null) {
  throw new IllegalStateException(format("Unsupported protocol in redirect of %s to %s", response.request().url(), location));
 }
 Request.Builder redirectRequest = response.request().newBuilder();
 redirectRequest.post(response.request().body());
 response.body().close();
 return doCall(prepareOkHttpClient(noRedirectOkHttpClient, postRequest), redirectRequest.url(url).build());
}
origin: testcontainers/testcontainers-java

@Override
@SneakyThrows
public <T> T post(Object entity, TypeReference<T> typeReference) {
  Request request = requestBuilder
    .post(RequestBody.create(MediaType.parse("application/json"), objectMapper.writeValueAsBytes(entity)))
    .build();
  try (Response response = execute(request)) {
    String inputStream = response.body().string();
    return objectMapper.readValue(inputStream, typeReference);
  }
}
origin: testcontainers/testcontainers-java

@Override
public <T> void post(TypeReference<T> typeReference, ResultCallback<T> resultCallback, InputStream body) {
  Request request = requestBuilder
    .post(toRequestBody(body, null))
    .build();
  executeAndStream(
    request,
    resultCallback,
    new JsonSink<>(objectMapper, typeReference, resultCallback)
  );
}
origin: graphhopper/graphhopper

protected String postJson(String url, JsonNode data) throws IOException {
  Request okRequest = new Request.Builder().url(url).post(RequestBody.create(MT_JSON, data.toString())).build();
  ResponseBody body = null;
  try {
    body = downloader.newCall(okRequest).execute().body();
    return body.string();
  } finally {
    Helper.close(body);
  }
}
origin: testcontainers/testcontainers-java

@Override
@SneakyThrows
public void postStream(InputStream body) {
  Request request = requestBuilder
    .post(toRequestBody(body, null))
    .build();
  execute(request).close();
}
origin: testcontainers/testcontainers-java

@Override
@SneakyThrows
public InputStream post(Object entity) {
  Request request = requestBuilder
    .post(RequestBody.create(MediaType.parse("application/json"), objectMapper.writeValueAsBytes(entity)))
    .build();
  return execute(request).body().byteStream();
}
origin: SonarSource/sonarqube

private static Request buildHttpRequest(HttpUrl url, WebhookPayload payload) {
 Request.Builder request = new Request.Builder();
 request.url(url);
 request.header(PROJECT_KEY_HEADER, payload.getProjectKey());
 if (isNotEmpty(url.username())) {
  request.header("Authorization", Credentials.basic(url.username(), url.password(), UTF_8));
 }
 RequestBody body = RequestBody.create(JSON, payload.getJson());
 request.post(body);
 return request.build();
}
origin: SonarSource/sonarqube

private Request buildHttpRequest(String json) {
 Request.Builder request = new Request.Builder();
 request.url(serverUrl);
 RequestBody body = RequestBody.create(JSON, json);
 request.post(body);
 return request.build();
}
origin: jeasonlzy/okhttp-OkGo

  @Override
  public Request generateRequest(RequestBody requestBody) {
    Request.Builder requestBuilder = generateRequestBuilder(requestBody);
    return requestBuilder.post(requestBody).url(url).tag(tag).build();
  }
}
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: apache/flink

public void send(DatadogHttpReporter.DatadogHttpRequest request) throws Exception {
  String postBody = serialize(request.getSeries());
  Request r = new Request.Builder()
    .url(seriesUrl)
    .post(RequestBody.create(MEDIA_TYPE, postBody))
    .build();
  client.newCall(r).enqueue(EmptyCallback.getEmptyCallback());
}
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

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 {
 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

private Request buildRequest(String hostname, int type) {
 Request.Builder requestBuilder = new Request.Builder().header("Accept", DNS_MESSAGE.toString());
 ByteString query = DnsRecordCodec.encodeQuery(hostname, type);
 if (post) {
  requestBuilder = requestBuilder.url(url).post(RequestBody.create(DNS_MESSAGE, query));
 } else {
  String encoded = query.base64Url().replace("=", "");
  HttpUrl requestUrl = url.newBuilder().addQueryParameter("dns", encoded).build();
  requestBuilder = requestBuilder.url(requestUrl);
 }
 return requestBuilder.build();
}
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());
 }
}
okhttp3Request$Builderpost

Popular methods of Request$Builder

  • build
  • url
  • <init>
  • addHeader
    Adds a header with name and value. Prefer this method for multiply-valued headers like "Cookie".Note
  • header
    Sets the header named name to value. If this request already has any headers with that name, they ar
  • get
  • method
  • cacheControl
    Sets this request's Cache-Control header, replacing any cache control headers already present. If ca
  • delete
  • put
  • headers
    Removes all headers on this builder and adds headers.
  • removeHeader
    Removes all headers named name on this builder.
  • headers,
  • removeHeader,
  • tag,
  • patch,
  • head

Popular in Java

  • Start an intent from android
  • getContentResolver (Context)
  • addToBackStack (FragmentTransaction)
  • scheduleAtFixedRate (ScheduledExecutorService)
  • URI (java.net)
    A Uniform Resource Identifier that identifies an abstract or physical resource, as specified by RFC
  • Permission (java.security)
    Legacy security code; do not use.
  • Properties (java.util)
    A Properties object is a Hashtable where the keys and values must be Strings. Each property can have
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • Project (org.apache.tools.ant)
    Central representation of an Ant project. This class defines an Ant project with all of its targets,
  • Top Sublime Text plugins
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