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 use a socks proxy with Java JDK HttpClient

NOTE: This is not a duplicate of https proxy with JDK11 client, which is about a HTTP proxy. My question is about a socks proxy, which requires a different solution. Neither is it a duplicate of How can I use HttpClient-4.5 against a SOCKS proxy?,…
Devabc
  • 4,782
  • 5
  • 27
  • 40
1
vote
1 answer

Mocking Java 11 HttpClient

I have this below piece of code which I'm trying to mock using power mock and mockito, but it is proving to be very difficult. Can someone explain on mocking the below code. HttpClient httpClient = HttpClient.newBuilder().authenticator(new…
1
vote
0 answers

jdk http client ntlm

I am not by far an expert in different protocols over http, but I can do this with curl to one of the APIs at my workplace: curl --http1.1 --ntlm -u 'user:pass' 'MY_URL' This works just fine. But notice that I can specify --ntlm. I am trying to…
Eugene
  • 117,005
  • 15
  • 201
  • 306
1
vote
2 answers

HTTP Authentication - Java Http Client is missing header that is present via curl

I'm trying to send a simple GET to an HTTP endpoint with java.net.http.HttpClient. The endpoint requires basic authentication. Simple enough, I'm doing what everyone's doing: HttpClient httpClient = HttpClient.newBuilder() …
1
vote
1 answer

How to get all effective HTTP request headers?

I want to use the new java.net.HttpClient to do some requests to another system. For debug purposes I want to log (and later store in our db) the request that I send and the response that I receive. How can I retrieve the effective http headers,…
slartidan
  • 20,403
  • 15
  • 83
  • 131
1
vote
1 answer

HttpClient hits timeout but server is available and working flawlessly

My problem is that the HttpClient never makes its way to the target. The target is on the same network (so I need no proxy) and it is definitely up. And the timeout was set quite high (120 seconds), the server is able to respond in less than a…
Marged
  • 10,577
  • 10
  • 57
  • 99
1
vote
0 answers

OutOfMemoryError when downloading large files with JDK HttpClient

I got OutOfMemoryError when I tried to download a large file (> 10GB) with JDK HttpClient. This only happened when I used BodyHandlers.ofInputStream. It didn't throw any error if I use BodyHandlers.ofFile. I am using JDK 11. Does anybody know how to…
Franz Wong
  • 1,024
  • 1
  • 10
  • 32
1
vote
1 answer

Why do I get HTTP Response Status Code 451 only when using the Java HTTP Client?

I want to make a GET-request, which works fine with OkHttpClient, my webbrowsers and postman. But when I use the Java HTTP Client, I receive the Response Code 451. This is my code: HttpClient client = HttpClient.newHttpClient(); …
Julian
  • 64
  • 6
1
vote
2 answers

How to submit HTTP request with an INTENTIONAL syntax error?

I'm trying to write a simple test where I submit a request to http://localhost:12345/%, knowing that this is an illegal URI, because I want to assert that my HTTP Server's error-handling code behaves correctly. However, I am having a hard time…
Andrew Rueckert
  • 4,858
  • 1
  • 33
  • 44
1
vote
0 answers

Reading HTTP headers as they become available

I currently have the need to read HTTP headers as they are sent. I have tried the new Java 11 HTTP client (java.net.http.HttpClient), but I have no luck intercepting the headers, as they are not available until the content is starting to be sent (so…
Morten Haraldsen
  • 1,013
  • 12
  • 24
1
vote
0 answers

Proxy does not work in java 11 httpclient

For some reason the first request passes successfully, and the second knocks out an error 502. With a proxy all is good, I tried to send the second request through postman using this proxy and everything worked perfectly. What could be the…
Anton
  • 11
  • 3
1
vote
1 answer

GOAWAY BItBucket API using java.net.http.HttpClient

Using java.net.http.HttpClient to send the request to BitBucket API with the following config: var url = "https://bitbucket.org/api/2.0/repositories/asomov/snakeyaml/issues/377"; HttpClient client = HttpClient.newBuilder() …
1
vote
0 answers

"Connection reset by peer" for Java HttpClient request

I'm using SpringBoot with JDK 11. This application is deployed on a container (AWS). Into my REST Controllers I need to call internally external REST api services (using TLS 1.2) I'm using java.net.http.HttpClient for this. httpClient =…
Safari
  • 11,437
  • 24
  • 91
  • 191
1
vote
1 answer

Java Async HttpClient request seems to block the main thread?

According to this the following snippet should be Async. Therefore, the output should read: TP1, TP2, TP3, http://openjdk.java.net/. However, when I run it I get: TP1, TP2, http://openjdk.java.net/, TP3. It seems "sendAsync" is blocking the main…
Adrian Smith
  • 1,013
  • 1
  • 13
  • 21
1
vote
1 answer

Using net.http.HttpClient in Tomcat causes memory leak

I'm using the Java's new (since version 11) HttpClient within a Servlet based web application: private static final HttpClient HTTP_CLIENT = .connectTimeout(Duration.ofSeconds(5)) .followRedirects(HttpClient.Redirect.NORMAL) …
Brice Roncace
  • 10,110
  • 9
  • 60
  • 69