Please note before configuration: Java needs to be executed in an non-mainland network network environment for IPFoxy proxy to take effect.
After purchasing a rotating proxy, go to the [Rotating Residential Proxy] page and complete the following operations:
1. Protocol type: http
2. Format: Username: Password@Host:Port
3. Generate Proxy
4. Copy the generated connection information
1. Copy the following code into the Java code and fill in the authUser and authPassword variables
import java.net.*;
import java.io.*;
import java.util.Scanner;
public class Main
{
public static void main(String[] args) throws Exception
{
final String authUser = "username";
final String authPassword = "password";
InetSocketAddress proxyAddress = new InetSocketAddress("gate-us.ipfoxy.io", 58688); // Set proxy IP/port.
Proxy proxy = new Proxy(Proxy.Type.HTTP, proxyAddress);
URL url = new URL("https://lumtest.com/myip.json"); //enter target URL
Authenticator authenticator = new Authenticator() {
public PasswordAuthentication getPasswordAuthentication() {
return (new PasswordAuthentication(authUser,authPassword.toCharArray())); //enter credentials
}
};
System.setProperty("http.proxyUser", authUser);
System.setProperty("http.proxyPassword", authPassword);
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
Authenticator.setDefault(authenticator);
URLConnection urlConnection = url.openConnection(proxy);
Scanner scanner = new Scanner(urlConnection.getInputStream());
for (; ; ) {
if (scanner.hasNext()) {
System.out.print(scanner.next());
}else{
break;
}
}
scanner.close();
}
}