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