java使用代理发送http请求
2018-07-20 来源:open-open
//一种方法是设置全局的代理,在程序中如下设置:
System.setProperty("proxySet", "true");
System.setProperty("http.proxyHost", "192.168.7.33");
System.setProperty("http.proxyPort", "8080");
//还有一种就是在发送每次请求的时候设置代理:
URL url = new URL("http://www.open-open.com");
Proxy proxy = new Proxy(Proxy.Type.DIRECT.HTTP, new InetSocketAddress("192.168.7.33", 8080));
HttpURLConnection conn = (HttpURLConnection) url.openConnection(proxy);
InputStream in = conn.getInputStream();
BufferedReader bin = new BufferedReader(new InputStreamReader(in));
String s = null;
while((s=bin.readLine())!=null){
System.out.println(s);
}
bin.close();
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点!
本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。
上一篇:快速排序C实现代码
下一篇: Windows移动硬盘修复工具C源代码
最新资讯
热门推荐