公司使用代理上网
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 阅读(951) 评论(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
    晕了,你这个就可以了,厉害,自己设置代理就不行.郁闷到头了  回复  更多评论   

只有注册用户登录后才能发表评论。


网站导航: