qq_哈哈_49
public class Test {
static String sendGet(String url) throws IOException{
String result="";
BufferedReader in=null;
try {
URL realUrl=new URL(url);
URLConnection connection=realUrl.openConnection();
connection.connect();
in= new BufferedReader(new InputStreamReader(connection.getInputStream(),"UTF-8"));
String line;
while ((line=in.readLine())!=null){
result+=line;
}
} catch (MalformedURLException e) {
System.out.print("发送GET请求出现异常!" + e);
e.printStackTrace();
}
finally{
try {
if (in != null) {
in.close();
}
} catch (Exception e2) {
e2.printStackTrace();
}
}
return result;
}
public static void main(String[] args) throws IOException{
String url="http://www.imooc.com/wenda/detail/314289";
String result=sendGet(url);
System.out.println(result);
}
}