Send your first Java request through a proxy
No extra downloads: Java's built-in HttpClient sends the request, and a short Authenticator block supplies your login.
Three steps to see it working
First, buy a plan. Datacenter costs less than the other types, so it suits a first test. Second, copy four details from your dashboard: the host (the proxy server's name or IP address), the port (a number written after the host, with a colon in between), your username and your password. Third, paste them into the sample below. Your login replaces USERNAME and PASSWORD, while gateway.proxy:8080 stands in for your host and port, so swap yours in wherever those appear. Then run it. The sample asks a website which IP address it can see, and if the answer isn't your own IP, the proxy is doing its job. It relies on a library (ready-made code that sends web requests for you); the libraries listed further down need the same details, though each has its own place to put them. Keep in mind that a proxy only changes the address a site sees, so your script must still follow that site's terms and the law where you live.
import java.net.*;
import java.net.http.*;
var proxy = new ProxySelector() {
public java.util.List<Proxy> select(URI u) {
return java.util.List.of(new Proxy(Proxy.Type.HTTP,
new InetSocketAddress("gateway.proxy", 8080)));
}
public void connectFailed(URI u, SocketAddress a, java.io.IOException e) {}
};
Authenticator.setDefault(new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("USERNAME", "PASSWORD".toCharArray());
}
});
var client = HttpClient.newBuilder().proxy(proxy).build();
var req = HttpRequest.newBuilder(URI.create("https://api.ipify.org")).build();
System.out.println(client.send(req, HttpResponse.BodyHandlers.ofString()).body());