Skip to content

Instantly share code, notes, and snippets.

@quantumproxies
Created July 28, 2026 09:47
Show Gist options
  • Select an option

  • Save quantumproxies/ab2ad9c1e5755038f87bd8673c805f7f to your computer and use it in GitHub Desktop.

Select an option

Save quantumproxies/ab2ad9c1e5755038f87bd8673c805f7f to your computer and use it in GitHub Desktop.
Java 11+ HttpClient through an authenticated proxy — fixes the 407 Basic-auth tunneling gotcha — https://quantumproxies.io/residential-proxies
// Java 11+ HttpClient through an authenticated residential proxy.
//
// THE GOTCHA: since JDK 8u111, Basic auth on HTTPS tunnels is disabled by
// default. Without the system property below you get "407 Proxy
// Authentication Required" forever, even with a correct Authenticator.
//
// java -Djdk.http.auth.tunneling.disabledSchemes= JavaProxyExample.java
//
// Proxy: QuantumProxies residential — https://quantumproxies.io/residential-proxies
// Credentials: https://app.quantumproxies.io/register
import java.net.*;
import java.net.http.*;
public class JavaProxyExample {
public static void main(String[] args) throws Exception {
String user = System.getenv().getOrDefault("QP_USER", "YOUR_USERNAME") + "-country-us";
String pass = System.getenv().getOrDefault("QP_PASS", "YOUR_PASSWORD");
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress(
"residentialboson.quantumproxies.io", 9000)))
.authenticator(new Authenticator() {
@Override protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, pass.toCharArray());
}
})
.build();
HttpResponse<String> res = client.send(
HttpRequest.newBuilder(URI.create("https://ipinfo.io/json")).build(),
HttpResponse.BodyHandlers.ofString());
System.out.println(res.body());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment