您的位置:首页 > 理论基础 > 计算机网络

利用httpURL 创建代理

2010-10-28 20:44 495 查看
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+"--------------");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息