Android 小型项目网络框架 http-request

码农软件 · 软件分类 · 手机开发工具 · 2019-04-30 15:44:50

软件介绍

http-request 是 Android 网络框架,在小型的项目上性能表现最好。

使用:

The http-request library is available from Maven Central.

<dependency>
  <groupId>com.github.kevinsawicki</groupId>
  <artifactId>http-request</artifactId>
  <version>6.0</version>
</dependency>

简单的AsyncTask异步加载示例:

private class DownloadTask extends AsyncTask<String, Long, File> {
  protected File doInBackground(String... urls) {
    try {
      HttpRequest request =  HttpRequest.get(urls[0]);
      File file = null;
      if (request.ok()) {
        file = File.createTempFile("download", ".tmp");
        request.receive(file);
        publishProgress(file.length());
      }
      return file;
    } catch (HttpRequestException exception) {
      return null;
    }
  }

  protected void onProgressUpdate(Long... progress) {
    Log.d("MyApp", "Downloaded bytes: " + progress[0]);
  }

  protected void onPostExecute(File file) {
    if (file != null)
      Log.d("MyApp", "Downloaded file to: " + file.getAbsolutePath());
    else
      Log.d("MyApp", "Download failed");
  }
}

new DownloadTask().execute("http://google.com");

本文地址:https://codercto.com/soft/d/4723.html

编程人生

编程人生

Peter Seibel / 图灵俱乐部 / 人民邮电出版社 / 2011-1-1 / 79.00元

界顶尖的程序员是怎么走上编程道路的? 他们的编程工作创造和改变了人类历史,在这一过程中都有哪些经验和教训? 他们对计算机软件行业的过去、现在和未来有什么独到的看法和见解? 他们对培养、发现、选拔、面试优秀的程序员有什么建议? 放下手头的工作,听听这些软件先驱们的故事和建议,眼界可以更开阔,思路可以更清晰,方向可以更明确,人生可以更精彩。 作者Peter Seibel采......一起来看看 《编程人生》 这本书的介绍吧!

随机密码生成器
随机密码生成器

多种字符组合密码

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具