I need to replace Apache http client with java httpClient.
I have a test with an apache client that works well:
HttpOptions httpOptions = new HttpOptions(uploadUrl);
try (CloseableHttpResponse responseOld = httpclient.execute(httpOptions)) {
assertEquals(200, responseOld.getStatusLine().getStatusCode());
assertEquals("POST,OPTIONS", responseOld.getFirstHeader("Access-Control-Allow-Methods").getValue());
}
But when I change it to java client, it doesn't work. I use this code:
HttpClient javaClient = HttpClient.newBuilder().sslContext(initUnsecuredSSLContext()).build();
HttpRequest get = HttpRequest.newBuilder()
.uri(URI.create(uploadUrl))
.method("OPTIONS", HttpRequest.BodyPublishers.noBody())
.build();
HttpResponse<String> response = javaClient.send(get, HttpResponse.BodyHandlers.ofString());
Test fails to complete when run
java version "17.0.2".
Thanks.