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
1
vote
1 answer

How to release the http connection

I call below code within my application. The first request is always working fine. My issue is that every following request is not sent, it runs into timeout, when I specify a timeout value. Otherwise it seems to wait endlessly. It seems the first…
MoxxiManagarm
  • 8,735
  • 3
  • 14
  • 43
1
vote
2 answers

Best approach to log entire HttpRequest

I have a library that perform http requests to a series of external APIs. This library is a SDK that every other projects can import to use inside. I am adding a lot of logs inside my library and, in some steps, I would like to log the HttpRequest…
user866364
1
vote
1 answer

How to measure the elapsed time of ASYNC sent HTTPRequest with Java 11 standard HTTPClient?

In one method, I create and send some HTTPRequests async, and add the CF to a list: // HTTPClient is Java11 standard, package java.net.http; CompletableFuture> httpResponseCF = this.httpClient.sendAsync(httpRequest,…
rranke
  • 33
  • 3
1
vote
1 answer

java.net.http HttpClient goes into loop wrapBuffer returned Status = OK HandshakeStatus = NEED_WRAP

I cannot post this into JDK bug report, because I cannot reproduce it beyond my corporate infrastructure setup, but maybe somebody has encountered something similar. Java version: 11.0.6 The code to build HttpClient: return HttpClient.newBuilder() …
Mr.Robot
  • 397
  • 8
  • 21
1
vote
0 answers

java.net.http Client Timeout & Connection Management / Address Resolution

We've defined a HTTPClient bean in Spring Boot the following way: @Configuration public class HttpClientConfig { @Bean HttpClient httpClient() { return HttpClient.newBuilder() .followRedirects(HttpClient.Redirect.ALWAYS) …
nmarques
  • 151
  • 12
1
vote
1 answer

Java 11 HttpClient cannot call React development server

Java 11's new HttpClient doesn't work with create-react-app's React development server (which starts via npm start). The client hangs indefinitely w/o any error. It works with other URLs https://google.com and other local servers like Node.js…
destan
  • 4,301
  • 3
  • 35
  • 62
1
vote
0 answers

Retrieving Java 11 HTTP Client Cookie

Here is some bash code that works: COOKIE_FILE=cookies.txt DOMAIN="http://localhost:9000" function login { URL_LOGIN="$DOMAIN/asfd/asdf" rm -f "$COOKIE_FILE" curl -s \ -H "Content-type: application/x-www-form-urlencoded" \ -c…
Mike Slinn
  • 7,705
  • 5
  • 51
  • 85
1
vote
1 answer

Make the new JDK 11 java.net.http package visible in Netbeans 10

After opening an existing Netbeans 8 project in Apache Netbeans 10, and setting the Java version to the newest JDK 11, Netbeans is still unable to resolve references to the new java.net.http package which includes improved HTTP handling with classes…
Bobulous
  • 12,967
  • 4
  • 37
  • 68
1
vote
5 answers

How do you read and print a chunked HTTP response using java.net.http as chunks arrive?

Java 11 introduces a new package, java.net.http, for making HTTP requests. For general usage, it's pretty straight forward. My question is: how do I use java.net.http to handle chunked responses as each chunk is received by the client? java.http.net…
hohonuuli
  • 1,974
  • 15
  • 15
0
votes
0 answers

Java 11 - HttpClient - JIRA - FileUploadBase$InvalidContentTypeException

Im trying to upload a file to a JIRA task using the Java 11 HttpClient. But getting org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't contain a multipart/form-data or multipart/mixed stream, content type…
VinodKhade
  • 147
  • 1
  • 2
  • 10
0
votes
1 answer

Can't use the java.net.http module/package in an android studio project

I'm using Android Studio Electric Eel | 2022.1.1 for a school project and I need to use an API. In order to use the API I need to send an HTTP request to a certain URL. I read about java 11's HttpClient and HttpRequest from the package java.net.http…
eladGN
  • 13
  • 3
0
votes
3 answers

How to stub HttpClient send method in mockito

I am calling an external API using HttpClient as below, HttpClient client = HttpClient.newHttpClient(); HttpRequest request = HttpRequest.newBuilder().uri(URI.create("http://localhost:8080/api")) …
BSM
  • 173
  • 3
  • 13
0
votes
2 answers

I am trying to stream response(word by word) of chatgpt api in android (java) by implementing async task but i get an error

I am trying to stream response(word by word) of chatgpt api in android (java) by implementing async task but i get an error. I am using java's HTTPurlconnection library with input and outputstreams so that I can stream response of chatgpt as in its…
0
votes
0 answers

Java Httpclient request to a site with self-signed certificate passes even after removing certificate from truststore

I am running a Java 11 SDK program through IntelliJ IDEA (on Widows 10) which is using the Java 11 Httpclient to send a simple GET request to a site that has a self-signed certificate. final HttpClient httpClient = HttpClient.newBuilder() …
0
votes
1 answer

java.net.http package can't be resolved in android kotlin project

I'm working on an simple android kotlin project which use the build-in java.net.http.HttpClient to make http post request, but it always failed to build, the error is: Unresolved reference: http Unresolved reference: HttpClient Unresolved reference:…
realjin
  • 1,485
  • 1
  • 19
  • 38