java访问https的代码

想让java通过http代理连接到网络,怎么设置代理的域名,用户名,密码?关键是代理的域名,域名

  1. System.getProperties().put("http.proxySet""true");   
  2. System.getProperties().put("http.proxyHost""host");   
  3. System.getProperties().put("http.proxyPort""port");   
  4. Authenticator.setDefault(new DefaultAuthenticator());   
  5. URL url = new URL("http://www.baidu.com");   
  6. URLConnection conn = url.openConnection();   
  7.   
  8. //代理域名,用户名,密码设置如下:   
  9. public class DefaultAuthenticator extends Authenticator {   
  10.     private static String username = "username";   
  11.     private static String domain = "domain";   
  12.     private static String password= "password";   
  13.   
  14.     public PasswordAuthentication getPasswordAuthentication() {   
  15.         String userNameWithDomain = domain + "\\" + username;   
  16.         return (new PasswordAuthentication(userNameWithDomain, password.toCharArray()));   
  17.     }   
  18. }  
  1. da shang
    donate-alipay
               donate-weixin weixinpay

发表评论↓↓