HttpURLConnection与代理服务器

String proxy = "proxy.jlu.edu.cn", port = "8080", username = "***", password = "***"; Authenticator .setDefault(new SimpleAuthenticator(username, password)); Properties systemProperties = System.getProperties(); systemProperties.setProperty("http.proxyHost", proxy); systemProperties.setProperty("http.proxyPort", port);

import java.net.Authenticator; import java.net.PasswordAuthentication; public class SimpleAuthenticator extends Authenticator { private String username, password; public SimpleAuthenticator(String username, String password) { this.username = username; this.password = password; } protected PasswordAuthentication getPasswordAuthentication() { return new PasswordAuthentication(username, password.toCharArray()); } }

 

 

 

你可能感兴趣的:(String,properties,服务器,Class,import)