给代码更好啊
9 回答
已采纳
qq_哈哈_49
TA贡献2条经验 获得超2个赞
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); } }
- 9 回答
- 1 关注
- 2107 浏览
相关问题推荐
添加回答
举报
0/150
提交
取消