欢迎访问悦橙教程(wld5.com),关注java教程。悦橙教程  java问答|  每日更新
页面导航 : > > 文章正文

java使用代理发送http请求,java代理发送请求, //一种方法是设

来源: javaer 分享于  点击 18817 次 点评:39

java使用代理发送http请求,java代理发送请求, //一种方法是设


    //一种方法是设置全局的代理,在程序中如下设置:      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();  
相关栏目:

用户点评