import java.net.Authenticator;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.ProxySelector;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
public class Main {
public static void main(String[] args) throws Exception {
// ==================== Proxy Configuration (Replace with your actual credentials) ====================
String username = "YOUR_USERNAME"; // Replace with the username from YumiProxy dashboard
String password = "YOUR_PASSWORD"; // Replace with the password from YumiProxy dashboard
String host = "proxy.yumiproxy.com"; // Replace with the proxy server address from the dashboard
int port = 9091; // Replace with the port from the dashboard
// Create an HttpClient with proxy and authenticator
HttpClient client = HttpClient.newBuilder()
.proxy(ProxySelector.of(new InetSocketAddress(host, port)))
.authenticator(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password.toCharArray());
}
})
.build();
// Build the GET request
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("https://ipinfo.io/json"))
.build();
// Send the synchronous request and get the response as a string
HttpResponse<String> response = client.send(
request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
}
}