Connect Java to your proxy plan
Scheduled data pulls behind your reports can use the proxy from OkHttp, Apache HttpClient or the HttpClient bundled with Java.
Set up once, then roll out to the team
One person can handle the setup for everyone. After the order is confirmed, copy the host, port and login from your dashboard into the sample below in place of USERNAME, PASSWORD and gateway.proxy:8080. Run it once and look at the address it returns: it should be a proxy IP, not your own. Then add the same settings to each script your team runs, keep every job within the target site’s terms, and store the login with your other work passwords rather than in a shared document.
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());