Trying to make a simple get request using java.net.http.HttpClient
.
it works without the proxy usage. Proxy is valid and working. Proxy supports https/s and socks5 connections. However when i try to use the proxy as in the example, receiving this error:
java.io.IOException: HTTP/1.1 header parser received no bytes
I think i pass proxy into the client correctly (as in example here https://openjdk.java.net/groups/net/httpclient/recipes.html ), although i pass the proxy IP, not the domain, which is seems to be accepted by InetSocketAddress
.
example:
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://google.com"))
.headers("Content-Type", "application/json;charset=UTF-8")
.GET()
.build();
HttpResponse<String> response = HttpClient
.newBuilder()
.connectTimeout(Duration.ofSeconds(15))
.proxy(ProxySelector.of(
new InetSocketAddress(
"1.1.1.1", 1111
)
))
.build()
.send(request, HttpResponse.BodyHandlers.ofString());