具体可以在穿云云代理后台操作:https://console.cloudbypass.com/#/proxy/account

// Use Java to request https://example.com/
import java.net. * ;
import java.io. * ;
public class ProxyConnect {
public static void main(String[] args) throws MalformedURLException,
ProtocolException,
IOException {
final String authUser = "";
final String authPassword = "";
final String proxyHost = "";
final int proxyPort = ;
final String destURL = "https://example.com/";
System.setProperty("jdk.http.auth.tunneling.disabledSchemes", "");
System.setProperty("jdk.http.auth.proxying.disabledSchemes", "");
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, proxyPort));
URL url = new URL(destURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection(proxy);
Authenticator.setDefault(new Authenticator() {@Override
protected PasswordAuthentication getPasswordAuthentication() {
if (getRequestorType().equals(RequestorType.PROXY)) {
return new PasswordAuthentication(authUser, authPassword.toCharArray());
}
return super.getPasswordAuthentication();
}
});
StringBuilder content;
try (BufferedReader in =new BufferedReader(new InputStreamReader(connection.getInputStream()))) {
String line;
content = new StringBuilder();
while ((line = in.readLine()) != null) {
content.append(line);
content.append(System.lineSeparator());
}
System.out.println(content.toString());
} catch(Throwable e) {
System.err.println(e);
} finally {
connection.disconnect();
}
}
}注意:穿云代理IP仅提供海外动态代理IP,在中国大陆IP环境下直连时可能会出现不稳定的情况,但您可以通过以下两种方式解决:一是将其部署在香港等境外服务器上使用;二是在本地电脑端开启TUN模式的全局代理进行中转。