Questions tagged [java-http-client]

This tag should be used for questions which relate specifically to the new JDK 11 `java.net.http` package which includes new classes and interfaces such as HttpClient, HttpRequest, HttpResponse, and WebSocket. This tag should not be used for questions which relate to HTTP handling with the older `java.net` package. This tag can be used for questions about the incubator versions of this package, but do make the JDK version clear in such cases.

This tag should be used for questions which relate specifically to the new Java HTTP Client and WebSocket APIs in package java.net.http which was formally introduced in JDK 11 and includes new classes and interfaces such as HttpClient, HttpRequest, HttpResponse, and WebSocket.

This tag should not be used for questions which relate to HTTP handling with the older java.net package, and it should not be used for questions about third-party HTTP libraries (such as Apache HttpClient, org.apache.http). Search the tags page for tags specific to third-party HTTP libraries.

Note that an incubator version of this new framework was included in JDK 9 and JDK 10. There are significant differences between the incubator versions and the finalised version which was released in JDK 11.

This tag can be used to ask questions about the incubator versions of this new package, but in such cases the question should clearly state the JDK version and make it clear that an incubator version of the framework is being discussed. Such questions should also be tagged with or to make it clear that an older JDK is being used.

179 questions
4
votes
2 answers

Using Java 11 HttpClient to read chunked data

I'm trying to read chunked data from an Http Response using Java 11's java.net.http.HttpClient, but I'm only getting one line at a time. I need to get an entire chunk at a time. Here's my code: final InputStream eventStream; try { …
liltitus27
  • 1,670
  • 5
  • 29
  • 46
4
votes
1 answer

NoClassDefFoundError while trying to use jdk.incubator.http.HttpClient in java in Eclipse Oxygen

Here is the code snippet that I use: HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder(URI.create("https://www.google.com")).GET().build(); HttpResponse.BodyHandler responseBodyHandler =…
Kavitha Karunakaran
  • 1,340
  • 1
  • 17
  • 32
3
votes
1 answer

How to limit connections for java.net.http.HttpClient

How to limit the number of connection/request for java.net.http.HttpClient? I see I can set an Executor to HttpClient but I don't know: if I limit the number of thread in pool of Executor, is it limit also the number of connection? Another way to…
lecogiteur
  • 307
  • 1
  • 7
  • 16
3
votes
1 answer

The failure retry mechanism of HttpClient in JDK11

I am currently using HttpClient in JDK11 (not Apache's HttpClient). These two HttpClients are similar, but I noticed that Apache's HttpClient can retry the request failure by overriding the HttpRequestRetryHandler class. But I did not find a similar…
3
votes
2 answers

How to follow-through on HTTP 303 status code when using HttpClient in Java 11 and later?

When using the java.net.http.HttpClient classes in Java 11 and later, how does one tell the client to follow through an HTTP 303 to get to the redirected page? Here is an example. Wikipedia provides a REST URL for getting the summary of a random…
Basil Bourque
  • 303,325
  • 100
  • 852
  • 1,154
3
votes
1 answer

Java HttpClient with TLS/SSLContext through proxy

I want to make a HTTP call to server that uses TLS to authenticate. Moreover server needs my IP to be whitelisted, so with AWS Lambda I need to use proxy. What I want to achieve is HTTP POST request with TLS that goes through proxy. To achieve TLS…
3
votes
0 answers

504 Gateaway Timeout when using Java HttpClient

I have a service listening in HTTP called by POST. Using software like curl, Postman, etc, the request is successful (status code 200). I need to consume this service from Java. But using the native HttpClient from Java 11, I get a 504 Gateway…
Johny
  • 809
  • 9
  • 19
3
votes
0 answers

Resilient HTTP client with name resolution update and active monitoring

I am trying to build an HTTP client based on java.net.http.HttpClient and I would like to have some control on the IP addresses resolved under the hood. I would like such mechanism to use all the IP addresses behind the host of the request. The…
Nicolas Henneaux
  • 11,507
  • 11
  • 57
  • 82
3
votes
2 answers

How to add headers based on multiple conditions to HttpRequest Java 11?

I'm learning the java.net.http api, trying to download a file given a range of bytes already downloaded. For this the range header can be used (supposing the server supports such feature). Using org.apache.http.client.methods.HttpGet I can do…
tec
  • 999
  • 3
  • 18
  • 40
3
votes
1 answer

How can I send an HTTP request using HTTP/2 over TLS? (Java 11 HttpClient)

I am trying to create a proxy in a Java application that allows me to modify some aspects of HTTP requests. To do this, I open a ServerSocket on port 8080, configure a Proxy in Mozilla Firefox on that port and, for each connection, execute the…
PablooD9
  • 83
  • 7
3
votes
0 answers

Using java.net.http.HttpClient, how to bind to specific interface (for outgoing connections)?

How is it possible to bind to specific interface when using java.net.http.HttpClient (Java 11)? When I was using Apache HttpClient, it was setLocalAddress method.
Xdg
  • 1,735
  • 2
  • 27
  • 42
3
votes
2 answers

Use jdk.internal.net.http

I would like to use ResponseSubscribers.ByteArraySubscriber that is in jdk.internal.net.http. I use openjdk11. I tried 2 things : 1/ I added to maven compiler plugin exports module
Maryo
  • 483
  • 2
  • 13
  • 25
3
votes
1 answer

Java HttpRequest timeout unexpectedly throwing HttpConnectTimeoutException

Using the new java.net.http package released with JDK 11, an HttpRequest has been assembled with a deliberately low response timeout: HttpRequest.Builder builder =…
Bobulous
  • 12,967
  • 4
  • 37
  • 68
3
votes
1 answer

NullPointerException in jdk.incubator.httpclient

I'm trying to new use new shiny httpclient from JDK10. Code is pretty simple. I use synchronous HTTP call form multiple threads: private final HttpClient httpClient = HttpClient.newBuilder() .executor(Utils.newFixedThreadPoolExecutor(1,…
turbanoff
  • 2,439
  • 6
  • 42
  • 99
2
votes
0 answers

Java 11/17 HttpClient - How to try several IPs behind one hostname?

How can I configure Java's own "new" (Java 9/11/17) HttpClient to try more than the first found IP adress behind a hostname? There are (at least) two scenarios: A server with IPv4 and IPv6 support: > host localhost localhost has address…
Dirk Hillbrecht
  • 573
  • 5
  • 18