java使用代理發送http請求
//一種方法是設置全局的代理,在程序中如下設置:System.setProperty("proxySet", "true"); System.setProperty("http.proxyHost", "192.168.7.33"); System.setProperty("http.proxyPort", "8080"); //還有一種就是在發送每次請求的時候設置代理: URL url = new URL("http://www.baiduhome.net"); 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(); </pre>
本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!