利用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+"--------------");
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+"--------------");
相关文章推荐
- 利用fiddler工具调试android应用发送HttpURLConnection请求
- ASP.NET 2.0利用Httphandler实现URL重写(伪URL及伪静态)(转)
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Android网络:HTTP之利用HttpURLConnection访问网页、获取网络图片实例
- Android通过HttpURLConnection与HttpClient联网代理网关设置
- ASP.NET2.0利用httphandler实现URL重写(伪URL及伪静态)
- 文档库创建的子文件夹的URL显示为 http://[机器名]/.... 导致无法正常访问的问题解决办法
- Java Http连接中(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- Android通过HttpURLConnection与HttpClient联网代理网关设置
- 利用HttpURLConnection对象和Internet交互
- 谈谈Java利用原始HttpURLConnection发送POST数据
- HttpURLConnection----利用接口回调和多线程进行简单的文件下载
- JAVA HTTP连接(HttpURLConnection)中使用代理(Proxy)及其验证(Authentication)
- 代理网络环境下使用HttpURLConnection
- Java 利用 HttpURLConnection 读取页面 返回字节流(生成静态页面)
- HTTP文件上传请求格式详解,利用HttpURLConnection上传文件
- Android通过HttpURLConnection与HttpClient联网代理网关设置
- springmvc创建restful接口通过HttpURLConnection创建连接传递数据
- java 抓取网页内容,可设定代理(HttpURLConnection)
- HttpClient HttpURLConnection设置代理IP和端口