java用代理访问

 Properties prop = System.getProperties();
 prop.setProperty("http.proxyHost", "localhost");
 // 设置http访问要使用的代理服务器的端口
 prop.setProperty("http.proxyPort", "8118");

 

    Properties props = System.getProperties();
     props.setProperty("proxySet", "true");
     props.setProperty("http.proxyHost", "172.30.96.35");
     props.setProperty("http.proxyPort", "8080");
     props.setProperty("http.proxyUser", "uatxm990375");
     props.setProperty("http.proxyPassword", "Iccc2016");   

      URL url = new URL("http://www.baidu.com");
      InputStream in = url.openConnection().getInputStream();
      //方法二
      /*URL url = new URL("http://www.baidu.com");
      InputStream in = url.openStream();*/

 

posted @ 2016-05-07 18:22  Earic  阅读(387)  评论(0编辑  收藏  举报