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

Java HttpClient synchronous vs asynchronous request

The Java HttpClient can send either a synchronous or an asynchronous request. The synchronous method blocks until a response has been received, while the asynchronous does not. But what does this mean for a developer? Generally speaking, I assume…
Kotaka Danski
  • 451
  • 1
  • 4
  • 14
0
votes
1 answer

Explicitly setting `Content-Length` header in `java.net.http.HttpRequest`

I want to upload a file from InputStream over HTTP, and for this, I am using the new HttpClient provided as part of JDK11. When I try to set the Content-Length while creating a post request I get an IllegalArgumentException saying restricted header…
Pramod
  • 391
  • 5
  • 21
0
votes
1 answer

java.net.http.HttpClient - Why would HttpResponse.body be null?

My application connects to an internet resource using java.net.http.HttpClient. I would expect it to either connect and work, or to throw an exception - and this is how it always seems to work. However, looking through logs I can see for another…
Jakg
  • 922
  • 12
  • 39
0
votes
1 answer

java HttpClient asynchronous error handling

I want to use Java Http Client: java.net.http.HttpClient in asynchronous way. When I receive http response (any http code) or timeout I want to execute some custom Java code. I struggle to complete the body of error…
Hollow.Quincy
  • 547
  • 1
  • 7
  • 14
0
votes
1 answer

Builder cannot be converted to HttpRequest

Trying to make a get request in Java 17 using HttpClient. All documentation I find tells me I should be able to do: HttpClient client = HttpClient.newHttpClient(); URI uri = new URI("https://postman-echo.com/get"); HttpRequest request =…
0
votes
0 answers

Java Rest API to connect to Sharepoint

I am trying to connect to Sharepoint using java of my web application. I don't want to use Jshare or java-sharepoint as they are not in my organisations repository. If anyone has done it previously without them please share the code snippets or any…
GeekCoder
  • 150
  • 1
  • 14
0
votes
1 answer

Java 11 HttpClient Handshake Failure

I'm having issues retrieving the content from some HTTPS sites using the Java 11 HTTPClient. Here's the code I'm using: HttpClient client = HttpClient.newBuilder().build(); HttpRequest request = HttpRequest.newBuilder() …
James Baker
  • 1,143
  • 17
  • 39
0
votes
1 answer

Java net HttpClient: React to timeout in async call

My goal is to react to the timeout in an asyncronius call of the HttpClient. I find many information on how to set the different timeouts but I do not find any information on how to react to the timeout if it occures. The documentaton stating…
Febell
  • 43
  • 5
0
votes
1 answer

HttpClient sendAsync losing MDC logging information

I am using MDC Logger, which works correctly everywhere apart from when I'm sending a request using HttpClient async. The MDC data is not getting passed to next thread and which means they are not on ours logs. How am I able to get the new thread to…
wolfe111
  • 51
  • 2
0
votes
1 answer

Controller with suspend function causing netty.RoutingInBoundHandler - java.lang.NoClassDefFoundError: kotlinx/coroutines/ThreadContextElement

I am trying to create the simplest possible Controller suspend function which will call another endpoint. The learning purpose is to understand how to work with the Suspend function and Coroutine in Kotlin. For that, I create a suspend function as…
Jim C
  • 3,957
  • 25
  • 85
  • 162
0
votes
1 answer

java.net.http.HttpClient inside Kotlin Suspend Function: Unresolved reference: await

I am trying to code Http Request with Kotlin Coroutines as explained in this guide and that other guide As far as I can see, my code is quite close to both example: package com.tolearn.service import java.net.URI import…
Jim C
  • 3,957
  • 25
  • 85
  • 162
0
votes
1 answer

Java problem with communication between HttpClient and HttpServer

This is my first question here, so I apologize if not every information needed will be in this post. I'm having problem with communication between java.net.http.HttpClient and HttpServer. I send a request from application with HttpClient to…
0
votes
1 answer

Java HttpClient - converting HttpResponse to String[]

I am new to java HttpClient and am currently trying to create a RestServiceApplication, but i am unable to convert a HttpResponse to a String array in order to access the elements of the array. package com.example.restservice; import…
Kev
  • 3
  • 4
0
votes
1 answer

Wait for a POST request and get the posted contents from a server in Java

I have a server which I want two computers to communicate through - one sends a POST request, the other gets the posted contents, posts a result and the first one gets the posted contents. I know how to make a GET and POST request but how can I wait…
Loading BG
  • 131
  • 2
  • 9
0
votes
0 answers

How can I change the TLS extensions being used in Java HttpClient (SSLContext)

I am wondering how to change which TLS extensions are to be used in Java by editing the SSLSockets or by another means. This is how I am currently initializing my SSL using…
1 2 3
11
12