为什么我收到Connection Refused错误

时间:2015-04-01 08:25:28

标签: java

URL url;
    String site = "http://google.com/?q=jjj";
    try {
        url = new URL(site);
        URLConnection urlc = url.openConnection();
        urlc.addRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.3; WOW64; rv:36.0) Gecko/20100101 Firefox/36.0");
        InputStream stream;
        stream= urlc.getInputStream();
        for(int i = 0;i!= -1;i= stream.read()){
            System.out.print((char)i);
        }
        stream.close();
    } catch (Exception e) {
        e.printStackTrace();
    }

这是Exception: java.net.ConnectException: Connection refused: connect

0 个答案:

没有答案