公司使用代理上網
          System.setProperty("proxySet""true");
                  System.setProperty(
          "proxyHost""192.168.0.254");
                  System.setProperty(
          "proxyPort""8080");
          URL u
          =new URL("http://www.sun.com");
                  URLConnection uc
          =u.openConnection();
                  uc.connect();
                  InputStream is
          =uc.getInputStream();
                  
          if(is!=null)
                      System.out.println(
          "Proxy Success");
                  
                  InetAddress.getByName(
          "www.sun.com");
          使用url連接上去都可以獲得inputstream
          但是InetAddress.getByName(www.sun.com);就java.net.UnknownHostException: www.sun.com
          那么這個代理到底怎么設置啊,大俠們速度..急
          posted on 2008-12-03 12:52 object 閱讀(970) 評論(4)  編輯  收藏
          Comments
          • # re: 各位大俠幫我解決一下代理問題
            隔葉黃鶯
            Posted @ 2008-12-03 14:13
            import java.net.*;

            System.setProperty("proxySet", "true");
            System.setProperty("proxyHost", "10.80.38.33");
            System.setProperty("proxyPort", "80");
            URL u=new URL("http://www.sun.com");
            URLConnection uc=u.openConnection();
            uc.connect();
            InputStream is=uc.getInputStream();
            if(is!=null)
            System.out.println("Proxy Success");

            InetAddress[] addr = InetAddress.getByName("www.sun.com");
            println addr[0].getHostAddress();

            輸出
            Proxy Success
            72.5.124.61

            沒問題。在你的代理服務器上訪問一下www.sun.com看看  回復  更多評論   
          • # re: 各位大俠幫我解決一下代理問題[未登錄]
            object
            Posted @ 2008-12-03 16:06
            @隔葉黃鶯

            不行啊,兄弟,行我就不郁悶了  回復  更多評論   
          • # re: 各位大俠幫我解決一下代理問題[未登錄]
            sorcerer
            Posted @ 2008-12-03 16:55
            用httpclient試試,我用可以的.  回復  更多評論   
          • # re: 各位大俠幫我解決一下代理問題[未登錄]
            object
            Posted @ 2008-12-04 09:53
            @sorcerer
            暈了,你這個就可以了,厲害,自己設置代理就不行.郁悶到頭了  回復  更多評論   

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
           
          主站蜘蛛池模板: 金湖县| 灵武市| 武胜县| 苏尼特左旗| 永仁县| 高唐县| 金川县| 莲花县| 阿克陶县| 京山县| 潞西市| 镇原县| 太保市| 凌海市| 新河县| 佛山市| 韶山市| 望江县| 九江市| 行唐县| 长白| 屯昌县| 克东县| 侯马市| 江城| 钦州市| 常熟市| 广河县| 商河县| 鲜城| 南昌市| 达尔| 金山区| 武鸣县| 达孜县| 临夏县| 大埔区| 巴马| 大洼县| 长春市| 新蔡县|