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+"--------------");
利用httpURL 创建代理
最新推荐文章于 2024-06-04 13:45:14 发布
本文介绍了如何使用Java进行HTTP代理服务器的配置,并实现基于用户名密码的认证过程。通过设置系统的属性来指定代理服务器的地址及端口,进一步通过Base64编码对用户的认证信息进行加密处理,最终设置到HTTP请求头中完成授权。
375

被折叠的 条评论
为什么被折叠?



