Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

最简单的HttpURLconnection封装,CallBack方法执行在UI线程。支持get请求,post请求,支持文件上传和下载。

Notifications You must be signed in to change notification settings

winlong/UrlHttpUtils

Repository files navigation

UrlHttpUtils

最简单的UrlHttpUtils封装,CallBack方法执行在UI线程。支持get请求,post请求,支持文件上传和下载。

使用方法:

代码很简单,只有五个Java文件,建议下载后将Java文件拷贝到工程中使用。

封装的功能有:

一般的get请求
一般的post请求
上传单个文件(包含进度)
上传list集合文件
上传map集合文件
文件下载(包含进度)
图片下载(实现了图片的压缩)

使用示例

GET请求

String url = "https://www.baidu.com/";
UrlHttpUtil.get(url, new CallBackUtil.CallBackString() {
 @Override
 public void onFailure(int code, String errorMessage) {
 }
 @Override
 public void onResponse(String response) {
 }
});

POST请求

String url = "https://www.baidu.com/";
HashMap<String, String> paramsMap = new HashMap<>();
paramsMap.put("title","title");
UrlHttpUtil.post(url, paramsMap, new CallBackUtil.CallBackString() {
 @Override
 public void onFailure(int code, String errorMessage) {
 }
 @Override
 public void onResponse(String response) {
 }
});

上传文件

 File file = new File(Environment.getExternalStorageDirectory()+"/kwwl/abc.jpg");
 HashMap<String, String> paramsMap = new HashMap<>();
 paramsMap.put("title","title");
 UrlHttpUtil.uploadFile("url", file, "image",UrlHttpUtil.FILE_TYPE_FILE, paramsMap, new CallBackUtil.CallBackString() {
 @Override
 public void onFailure(int code, String errorMessage) {
 }
 @Override
 public void onResponse(String response) {
 }
 });

下载文件

 UrlHttpUtil.downloadFile("url", new CallBackUtil.CallBackFile("fileDir","fileName") {
 @Override
 public void onFailure(int code, String errorMessage) {
 }
 @Override
 public void onProgress(float progress, long total) {
 super.onProgress(progress, total);
 }
 @Override
 public void onResponse(File response) {
 }
 });

About

最简单的HttpURLconnection封装,CallBack方法执行在UI线程。支持get请求,post请求,支持文件上传和下载。

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 100.0%

AltStyle によって変換されたページ (->オリジナル) /