您的位置:首页 > 理论基础 > 计算机网络

Android25图灵聊天项目------HttpURLConnection请求get文本数据

2015-06-06 09:11 771 查看
String APIKEY = "开发者注册帐号,激活之后即可获得"; 
     String INFO = URLEncoder.encode("北京今日天气", "utf-8"); 
    String getURL = "http://www.tuling123.com/openapi/api?key=" + APIKEY + "&info=" + INFO; 
    URL getUrl = new URL(getURL); 
    HttpURLConnection connection = (HttpURLConnection) getUrl.openConnection(); 
    connection.connect(); 

    // 取得输入流,并使用Reader读取 
    BufferedReader reader = new BufferedReader(new InputStreamReader( connection.getInputStream(), "utf-8"));
    StringBuffer sb = new StringBuffer(); 
    String line = ""; 
    while ((line = reader.readLine()) != null) { 
        sb.append(line); 
    } 
    reader.close(); 
    // 断开连接 
    connection.disconnect(); 
    System.out.println(sb); 


源码下载:

http://download.csdn.net/detail/zhaihaohao1/8777931
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: