HttpURLConnection实现下载功能
来源:互联网 发布:腾讯微博 知乎 编辑:程序博客网 时间:2024/06/05 20:44
private String connectToTerminal(String urlStr) { LogUtils.i(TAG, "下载 url "+urlStr); LogUtils.i(TAG, "[jinxiuzhen]connectToTerminal();"); URL url = null; HttpURLConnection connection = null; InputStream is = null; String result = null; try { url = new URL(urlStr); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.setConnectTimeout(5000); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("X-API-KEY", LoginReceiver.keyToken); connection.setRequestProperty("url", urlStr); is = connection.getInputStream(); InputStreamReader isReader = new InputStreamReader(is); BufferedReader bufferedReader = new BufferedReader(isReader); String buffer = ""; StringBuilder sb = new StringBuilder(); while ((buffer = bufferedReader.readLine()) != null) { sb.append(buffer); } result = sb.toString(); LogUtils.i(TAG, "result=》"+result); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { if (is != null) { try { is.close(); } catch (IOException e) { e.printStackTrace(); } } if (connection != null) { connection.disconnect(); } } return result;}
1 0
- HttpURLConnection实现下载功能
- android HttpURLConnection 实现下载
- HttpUrlConnection实现文件下载
- HttpURLConnection实现文件下载
- HttpURLConnection实现多线程下载
- 使用HttpURLConnection实现多线程下载
- android HttpURLConnection实现多线程下载
- 使用HttpURLConnection实现文件下载
- HttpURLConnection实现多线程网络下载
- HttpUrlConnection实现多线程下载网络资源
- AsyncHttpClient实现上传 HttpURLConnection实现下载
- Android 使用HttpURLConnection实现多线程下载 笔记
- HttpURLConnection方式下载文件之实现断点续传
- android中使用HttpURLConnection实现多线程下载
- HttpURLConnection实现多线程下载资源contentLength()
- Android-使用HttpURLConnection实现多线程下载
- 利用HttpURLConnection实现远程下载文件
- Java使用HttpUrlConnection实现多线程断点下载
- butterknife 8.4.0
- zookeeper实现分布式锁
- android权限(permission)大全
- Android 异步加载图片,使用LruCache和SD卡或手机缓存,效果非常的流畅
- 智和网管平台SugarNMS能源行业综合网管解决方案
- HttpURLConnection实现下载功能
- oracle自增长序列
- 8.对Hello World程序的深入
- 字符串
- 数据库存储过程 PL-SQL
- Java数据结构和算法:图
- mysql实现oracle的分析函数lag和rank
- vue 前端框架
- android在程序代码中使用res目录下的String资源