Tabnine Logo
HttpRequest$Builder
Code IndexAdd Tabnine to your IDE (free)

How to use
HttpRequest$Builder
in
java.net.http

Best Java code snippets using java.net.http.HttpRequest$Builder (Showing top 10 results out of 315)

origin: svenkubiak/mangooio

/**
 * Simulates a FORM post by setting:
 * 
 * Content-Type to application/x-www-form-urlencoded
 * HTTP method to POST
 * URLEncoding of the given parameters
 * 
 * @param parameters The parameters to use
 * @return TestResponse instance
 */
public TestResponse withForm(Multimap<String, String> parameters) {
  String form = parameters.entries()
      .stream()
      .map(entry -> entry.getKey() + "=" + URLEncoder.encode(entry.getValue(), Charset.forName(Default.ENCODING.toString())))
      .collect(Collectors.joining("&"));
  
  this.httpRequest.header(CONTENT_TYPE, "application/x-www-form-urlencoded");
  this.body = BodyPublishers.ofString(form);
  this.method = Methods.POST.toString();
  
  return this;
}

origin: net.dongliu/xhttp

    httpRequestBuilder.GET();
    break;
  case DELETE:
    httpRequestBuilder.DELETE();
    break;
  default:
    httpRequestBuilder.method(request.method().name(), bodyPublisher);
httpRequestBuilder.uri(uri);
httpRequestBuilder.expectContinue(false);
body.ifPresent(b -> {
  var contentType = b.contentType();
  httpRequestBuilder.setHeader(HeaderNames.CONTENT_TYPE, contentType.toString());
});
httpRequestBuilder.timeout(request.timeout());
request.userAgent().ifPresent(ua -> httpRequestBuilder.setHeader(HeaderNames.USER_AGENT, ua));
request.referer().ifPresent(referer -> httpRequestBuilder.setHeader(HeaderNames.REFERER, referer));
  httpRequestBuilder.setHeader(HeaderNames.AUTHORIZATION, auth);
});
  httpRequestBuilder.setHeader(ACCEPT_ENCODING, COMPRESS_ENCODINGS);
    httpRequestBuilder.header(HeaderNames.COOKIE, cookie.name() + "=" + cookie.value());
  httpRequestBuilder.setHeader(header.name(), String.valueOf(header.value()));
origin: svenkubiak/mangooio

  this.url = "http://" + host + ":" + port;
  this.httpRequest
    .uri(new URI(this.url + this.uri))
    .method(this.method, this.body);
      .send(this.httpRequest.build(), HttpResponse.BodyHandlers.ofString());
} catch (URISyntaxException | IOException | InterruptedException e) {
  LOG.error("Failed to execute HTTP request", e);
origin: com.playtika.reactivefeign/feign-reactor-java11

@Override
public Mono<ReactiveHttpResponse> executeRequest(ReactiveHttpRequest request) {
  HttpRequest.Builder requestBuilder = HttpRequest.newBuilder(request.uri())
      .method(request.method().toUpperCase(), provideBody(request));
  setUpHeaders(request, requestBuilder);
  if(requestTimeout > 0){
    requestBuilder = requestBuilder.timeout(Duration.ofMillis(requestTimeout));
  }
  if(tryUseCompression){
    requestBuilder = requestBuilder.setHeader(ACCEPT_ENCODING_HEADER, GZIP);
  }
  Java11ReactiveHttpResponse.ReactiveBodySubscriber bodySubscriber = new Java11ReactiveHttpResponse.ReactiveBodySubscriber();
  CompletableFuture<HttpResponse<Void>> response = httpClient.sendAsync(
      requestBuilder.build(), fromSubscriber(bodySubscriber));
  return Mono.fromFuture(response)
      .<ReactiveHttpResponse>map(resp -> {
        if(!resp.version().equals(httpClient.version())){
          throw new IllegalArgumentException("Incorrect response version:"+resp.version());
        }
        return new Java11ReactiveHttpResponse(resp, bodySubscriber.content(),
            returnPublisherClass, returnActualClass,
            jsonFactory, responseReader);
      })
      .onErrorMap(ex -> ex instanceof CompletionException
               && ex.getCause() instanceof java.net.http.HttpTimeoutException,
          ReadTimeoutException::new);
}
origin: svenkubiak/mangooio

/**
 * Sets the timeout of the HTTP request
 * 
 * Default is 2 seconds
 *
 * @param amount The amount of time
 * @param unit The unit of time
 * 
 * @return TestResponse instance
 */
public TestResponse withTimeout(long amount, TemporalUnit unit) {
  Objects.requireNonNull(method, "method can not be null");
  this.httpRequest.timeout(Duration.of(amount, unit));
  
  return this;
}

origin: svenkubiak/mangooio

/**
 * Adds an additional header to the request
 *
 * @param name The name of the header
 * @param value The value of the header
 * @return TestResponse instance
 */
public TestResponse withHeader(String name, String value) {
  Objects.requireNonNull(name, "name can not be null");
  Objects.requireNonNull(value, "value can not be null");
  
  this.httpRequest.header(name, value);
  
  return this;
}

origin: svenkubiak/mangooio

private final void init() {
  this.httpRequest.timeout(Duration.of(TWO_SECONDS, ChronoUnit.SECONDS));
  this.httpClient.followRedirects(HttpClient.Redirect.ALWAYS);
  this.httpClient.cookieHandler(this.cookieManager);
}

origin: svenkubiak/mangooio

/**
 * Sets the ContentType of the request
 *
 * @param contentType The content type to use
 * 
 * @return TestResponse instance
 */
public TestResponse withContentType(String contentType) {
  Objects.requireNonNull(contentType, "contentType can not be null");
  this.httpRequest.header(CONTENT_TYPE, contentType);
  
  return this;
}

origin: com.playtika.reactivefeign/feign-reactor-java11

protected void setUpHeaders(ReactiveHttpRequest request, HttpRequest.Builder requestBuilder) {
  request.headers().forEach((key, values) -> values.forEach(value -> requestBuilder.header(key, value)));
  String contentTypeHeader = getContentTypeHeader(request);
  if(contentTypeHeader != null) {
    requestBuilder.header(CONTENT_TYPE_HEADER, contentTypeHeader);
  }
  requestBuilder.header(ACCEPT_HEADER, getAcceptHeader());
}
origin: com.playtika.reactivefeign/feign-reactor-java11

  private void upgradeToH2c(Target target){
    try {
      httpClient.send(HttpRequest.newBuilder()
          .method("options", HttpRequest.BodyPublishers.noBody())
          .uri(URI.create(target.url()))
          .build(),
          HttpResponse.BodyHandlers.discarding());
    } catch (IOException | InterruptedException e) {
      throw new RuntimeException(e);
    }
  }
}
java.net.httpHttpRequest$Builder

Most used methods

  • build
  • header
  • method
  • timeout
  • uri
  • setHeader
  • DELETE
  • GET
  • expectContinue

Popular in Java

  • Making http requests using okhttp
  • runOnUiThread (Activity)
  • setRequestProperty (URLConnection)
  • onCreateOptionsMenu (Activity)
  • Pointer (com.sun.jna)
    An abstraction for a native pointer data type. A Pointer instance represents, on the Java side, a na
  • SimpleDateFormat (java.text)
    Formats and parses dates in a locale-sensitive manner. Formatting turns a Date into a String, and pa
  • Stack (java.util)
    Stack is a Last-In/First-Out(LIFO) data structure which represents a stack of objects. It enables u
  • TimeUnit (java.util.concurrent)
    A TimeUnit represents time durations at a given unit of granularity and provides utility methods to
  • Modifier (javassist)
    The Modifier class provides static methods and constants to decode class and member access modifiers
  • HttpServlet (javax.servlet.http)
    Provides an abstract class to be subclassed to create an HTTP servlet suitable for a Web site. A sub
  • Github Copilot alternatives
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