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
2
votes
1 answer

streaming response body to a streaming request body with java 11 HttpClient

I'm trying stream the data from an HTTP (GET) response to another HTTP (POST) request. With old HttpURLConnection I would take the responses OutputStream, read parts into a buffer and write them to the requests InputStream. I've already managed to…
Jens
  • 495
  • 1
  • 6
  • 28
2
votes
1 answer

Does java.net.http.HttpClient need closing?

I'm using the new java.net.http.HttpClient and from my tests after about 378026 times of calling it, I start to get the following: Caused by: java.net.ConnectException: Cannot assign requested address at…
Arya
  • 8,473
  • 27
  • 105
  • 175
2
votes
1 answer

Is it possible to build a Java 11 HttpClient that uses SSL/TLS JAVA_OPTS as its SSLContext?

I know with Apache's HttpClientBuilder you can call useSystemProperties() and it will create a client with an SSLContext configured from the javax.net.ssl.keyStore (and truststore) if passed as JAVA_OPTS: try (CloseableHttpClient client =…
heez
  • 2,029
  • 3
  • 27
  • 39
2
votes
1 answer

Logging in JDK11 HttpClient

JDK11 introduced a new HTTP Client, with many features that lacks in traditional java.net.HttpURLConnection class. First question that I encountered with is how to properly enable logging in newly added HTTP Client?
Maxim Kirilov
  • 2,639
  • 24
  • 49
2
votes
1 answer

WildFly Service Module Loader - ClassNotFound on jdk.incubator.http.HttpClient

I am using WildFly15 with JDK 10 to build an application with the new HTTP Client and when I declare the jdk.incubator.httpclient as the only and single requirement in my module it works fine. (I can't go to JDK11 because we need to run in…
Evandro Pomatti
  • 13,341
  • 16
  • 97
  • 165
2
votes
1 answer

Using HttpBuilder API in Java 11, where do you specify the hostNameVerifier?

We are moving a service from JDK 10.0.1 to JDK 11. This service communicates using a TLS connection, where the server has a self-signed certificate. The CA of this certificate has been added to the cacerts of both JVM's. Using JDK 10, this was…
1
vote
1 answer

HttpClient Object in Java 11 OpenJDK

I'm using Java 11 HttpClient to send request to a remote server. I wanted to know if there is a difference on the HttpClient object when creating object in below 2 different ways HttpClient client = HttpClient.newHttpClient(); vs HttpClient client…
1
vote
1 answer

java.net.http httpclient sendasync consumer callback says unexpected return value

I am using Java 17. I am trying to get the response from a message service and create a map object. Then send it to the caller method. I am using java.net.http. I am willing to use a callback so that I could not use join or get to delay the main…
Sumon Bappi
  • 1,937
  • 8
  • 38
  • 82
1
vote
1 answer

generate CURL from java.net.http.HttpRequest

is there a good way to generate curl from java.net.http.HttpRequest? It seems like there is no good way to get the body (if there is a body), the closest thing to it is bodyPublisher() that returns Optional that has only long…
Roy Ash
  • 1,078
  • 1
  • 11
  • 28
1
vote
1 answer

I Am Getting The 200 Status Code But Instead I Should get 302 Status Code, How Do I Solve It?

I Was Making A Java Program That Can Check That We Will Redirect Or Not There Are Some Status Codes In HTTPS, Like 200 Is For OK And 302 Is For Redirect, So Heres My Code: URL url = new URL("http://localhost/test/test_page_1.php"); HttpURLConnection…
LakshyaK2011
  • 102
  • 10
1
vote
0 answers

How to process each part from multipart response in Java from javax.mail.internet.MimeMultipart API

ByteArrayDataSource datasource = new ByteArrayDataSource(in, "multipart/form-data"); MimeMultipart multipart = new MimeMultipart(datasource); int count = multipart.getCount(); log.debug("count " + count); for (int i = 0; i < count; i++) { …
1
vote
1 answer

Can the core Java HttpClient proxy through a TLS Proxy?

I am trying to setup a HttpClient to proxy requests through a HTTPS authenticated proxy. It seems the Java HttpClient can only proxy over http and therefore the proxy credentials are sent in plaintext to the proxy. I have opened the proxy on port…
donal
  • 13
  • 3
1
vote
0 answers

Java HttpClient is not returning latest data from API

I'm running this code in Idea 2020.1 with Java 11 (of course!) String gitApiPrUrl = "https://bitbucket.myserver.com/rest/api/1.0/projects/PRJ/repos/my-repo/pull-requests"; HttpRequest request = HttpRequest.newBuilder() …
Sree
  • 746
  • 6
  • 21
1
vote
0 answers

Java 11 HttpClient request not getting timeout

Using java11 Http Client as below, HttpClient httpClient = HttpClient.newBuilder() .version(HttpClient.Version.HTTP_1_1) .followRedirects(HttpClient.Redirect.NORMAL) …
Ganesh ram
  • 11
  • 4
1
vote
1 answer

Why does sendAsync HttpClient work sequentially if I'm not do collect inbetween?

During doing a tutorial about JDK11 HttpClient, using a https://httpstat.us/500?sleep=1000 endpoint which is returning HTTP 500 after 1 second, I prepared the following piece of code: HttpClient client = HttpClient.newHttpClient(); var futures =…
m.antkowicz
  • 13,268
  • 18
  • 37