JV
Languages & HTTP Clients
Java (OkHttp) proxy integration
OkHttp routes traffic through a java.net.Proxy and handles proxy auth with a proxyAuthenticator. Configure both and your Java requests tunnel through Aethyn residential IPs.
Setup steps
- 1Create a Proxy with the Aethyn host and port.
- 2Add a proxyAuthenticator that sets the Proxy-Authorization header.
- 3Build the OkHttpClient with both.
- 4Put targeting suffixes in the username.
Code
OkHttp client with proxy auth
import okhttp3.*;
import java.net.*;
Proxy proxy = new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("proxy.aethyn.io", 2099));
OkHttpClient client = new OkHttpClient.Builder()
.proxy(proxy)
.proxyAuthenticator((route, response) -> {
String cred = Credentials.basic("aethyn-XXXXX-country-us", "PASSWORD");
return response.request().newBuilder()
.header("Proxy-Authorization", cred).build();
})
.build();
Request req = new Request.Builder().url("https://httpbin.org/ip").build();
try (Response res = client.newCall(req).execute()) {
System.out.println(res.body().string());
}Replace aethyn-XXXXX and PASSWORD with your dashboard credentials. See the full targeting reference and protocol/port list.
Tips
- Reuse a single OkHttpClient — it pools connections and threads.
- Credentials.basic() builds the Proxy-Authorization value for you.
- Targeting goes in the username passed to Credentials.basic().
Java (OkHttp) proxy FAQ
Why an Authenticator instead of URL credentials?
OkHttp expects proxy credentials via a proxyAuthenticator that sets the Proxy-Authorization header, rather than embedding them in the proxy URL.
Docs, solutions & blog
Premium residential proxiesCost-efficient rotating residential pool from €2.00/GB for bulk scraping and monitoring.Elite residential proxiesCurated high-trust pool with city and ISP targeting for hard anti-bot targets.Quickstart docsCredentials, endpoints, and your first proxied request.Proxy glossaryPlain-English definitions for residential proxies, rotation, anti-bot, and scraping terms.