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
0
votes
2 answers

How to send DELETE request using HttpClient

how can I send an http DELETE request to this using HttpClient object or something similar? This is my code for GET and POST requests: public class Main { public static void main(String[] args) throws IOException, InterruptedException { …
user14021516
0
votes
1 answer

How to POST array of strings with Java 11 HttpClient?

Trying to call an interface which accepts two POST parameters: param1: string param2: Array[string] My attempt to post Array as just a String is obviously naive, but can't find a better way. What would be the right way to post a parameter…
Ninius86
  • 295
  • 6
  • 14
0
votes
1 answer

How do I prevent `java.IOException: HTTP1.1 header parser received no bytes`, when I need to wait for user to click a link in my app?

How do I wait for a my server to be updated? I am setting up my HttpServer and can get a response from my own status I pass in to the createContext handle with my GET method, but when I need to wait for the user (me) to click the Spotify auth link…
SimonA
  • 135
  • 2
  • 16
0
votes
2 answers

Why doesn't `HttpClient.newHttpClient()` work?

I try to learn using HTTPClient. But HttpClient client = HttpClient.newHttpClient(); does not work. In IntelliJ I've updated my compiler to use Java version 12 and in the pom.xml I've set java.version property to 12. After I write HTTPClient it…
Gioli
  • 55
  • 9
0
votes
2 answers

how to use Multiplexing http2 feature when uploading

There should be a significant improvement of performance using multiplexing http2 feature when uploading multiple files. And Java has an httpclient which supports natively the HTTP/2 protocol, so given that I tried to wrote the code for my own…
freedev
  • 25,946
  • 8
  • 108
  • 125
0
votes
1 answer

Changing Java's Native HTTP Client's proxy without building a new HTTP Client

I have a scraper that loops indefinitely, and I want to change the proxy on the client in case there is something wrong like an IP Ban (on 403 status code) or if I just want to change the proxy after each loop to avoid the bans completely. The…
0
votes
1 answer

Java 11 HttpClient does not allow headers starting by colon

I am trying to send a POST request (HTTP/2) with a header called ":path" but looks like HttpClient in java 11 does not allow headers starting by colon. This header should be fine using HTTP/2. That is how my code looks like: HttpClient…
Guti
  • 57
  • 1
  • 3
0
votes
1 answer

Mocking execte() method of HttpClient

I want to mock execute method of HttpClass to return a dummy response, but my test code is acutally executing the request. Class Code - class MyService { private CloseableHttpClient newHttpClient() { try { …
Vikash Yadav
  • 713
  • 1
  • 9
  • 29
0
votes
1 answer

Create a java.net.Authenticator with specific scope

I am using JDK11 HTTP client library, where I try to create an authentication with specific scope which can be related to host, port, realm or scheme(BASIC, DIGEST, etc.). My class implementation is: class CredentialsProviderAuthenticator extends…
Maxim Kirilov
  • 2,639
  • 24
  • 49
0
votes
1 answer

Printing blank lines HttpResponse JDK 11

I'm studying the new HttpClient from Java 11 and is not working properly. When I try to print the body from a website the body() method print blank lines: var httpClient = HttpClient.newHttpClient(); var request =…
Aldo Inácio da Silva
  • 824
  • 2
  • 14
  • 38
0
votes
1 answer

Creating a Hastebin Paste with Java

I am trying to make a java program that could I would give her a string, it would paste it to Hastebin(www.hastebin.com) and print the paste's URL to the console and this is the code I have: Main.java(Main class): public class Main { Hastebin…
Tal Moshel
  • 232
  • 3
  • 18
0
votes
1 answer

Java 9 HttpClient still in incubation?

Saw from Javadoc of HttpClient - Incubating Feature. Will be removed in a future release. And it doesn't seem to support application/x-www-form-urlencoded or multipart/form-data POST. See this post: Java 9 HttpClient send a multipart/form-data…
auntyellow
  • 2,423
  • 2
  • 20
  • 47
-1
votes
2 answers

How to pass a variable in JSON request body string for http POST

I currently have a JSON request body as a string that I am also passing as a string in the BodyPublishers.ofString() method when using the java httpclient to send a POST request. I also want to be able to include the variables below in my values…
wheelerlc64
  • 435
  • 2
  • 5
  • 17
-2
votes
1 answer

Upgrading Java 9 HttpClient code to Java 11: BodyProcessor and asString()

I have a code base which (apparently) works under Java 9 but does not compile under Java 11. It uses the jdk.incubator.httpclient API and changing the module information according to this answer works for the most part but more than the package has…
BullyWiiPlaza
  • 17,329
  • 10
  • 113
  • 185
1 2 3
11
12