利用httpURL 创建代理

Properties prop = System.getProperties();
    System.getProperties().put("proxySet","true");
    // 设置http访问要使用的代理服务器的地址
    prop.setProperty("http.proxyHost","172.17.0.2");
    // 设置http访问要使用的代理服务器的端口
    prop.setProperty("http.proxyPort","8080");
   httpURL = new URL(url);
   System.out.println("-----------url:"+url+"--------------");
   connection = (HttpURLConnection) httpURL.openConnection();
   System.out.println("-----------httpURL.openConnection()--------------");
   String authentication = "gaozhengyue:131421"; // 用户名密码
   String encodedLogin = new BASE64Encoder().encode(authentication.getBytes()); // 编码
   connection.setRequestProperty("Proxy-Authorization", " Basic " + encodedLogin);  // 授权
   System.out.println("-----------connection8.setRequestProperty:"+encodedLogin+"--------------");

你可能感兴趣的:(properties,String,服务器,url,basic,Authentication)