Hello,
We have a Linux box that has localhost IP address (127.XX.XX.XX ) followed by the internal IP address (10.XXX.XXX.XX) listed in it's host file.
Server when started up is bound to the internal IP address.
Our application uses Java 11/17 HTTP Client and the request is sent asynchronously
Code:
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://hostname.domain:port/path"))
.header("Content-Type", "application/json")
.POST(json.body))
.build()
When our application ran on the same linux box, we found that the HttpClient library picked up 1st IP address (127.XXX.XXX.XX) and threw ClosedChannelException.
Is there a way to tell Java's HTTPClient to try all assigned IP addresses or if there are any best practices to follow in scenarios where a host could potentially have multiple IP address and a Java application using JDK's HTTPClient needs to connect to such a host.
BTW, I rather use Java's inbuilt libs and also I really don't want to modify our codebase at this point to use Apache's HTTPClient.
Please advice.
Thank you.