GET请求示例
//所有参数都使用Bundle,用putString Bundle bundle = new Bundle(); bundle.putString("username", "RederXuGet"); bundle.putString("password", "farmerGet"); //url String url = "http://www.baidu.com"; //发起请求 HTTPRequest.GET(this,url, bundle, new onRequestOverListener() { @Override public void onRequestOver(String result) { //返回结果(或错误原因) Log.e("onRequestOver", result); } });
POST请求与GET请求的写法一致,只有调用方法不同。
POST请求示例
//所有参数都使用Bundle,用putString Bundle bundle = new Bundle(); bundle.putString("username", "RederXuGet"); bundle.putString("password", "farmerGet"); //url String url = "http://www.baidu.com"; //发起请求 HTTPRequest.POST(this,url, bundle, new onRequestOverListener() { @Override public void onRequestOver(String result) { //返回结果(或错误原因) Log.e("onRequestOver", result); } });
文件下载
String url = "http://192.168.1.174:8020/video1.mp4"; String path = "/mnt/sdcard/"; HTTPRequest.fileDownload(url, path,true, new onFileDownloadListener() { @Override public void onDownloading(int max, int progress) { // TODO Auto-generated method stub Log.e("下载进度", progress + "/" + max); } @Override public void onDownloadOver(String result) { Log.e("下载完成,存储位置:", result); } });
文件上传
String uploadUrl = "http://192.168.1.174:8020/android/FileUpload.php"; String filePath = "/mnt/sdcard/screenshot.png"; HTTPRequest.uploadFile(uploadUrl, filePath, new onRequestOverListener() { @Override public void onRequestOver(String result) { //服务端上传成功后返回的信息 Log.e("upload", result); } });
框架和DEMO文件下载地址 http://www.ideayapai.com/Application/Home/View/default/PowerFamily/index-2.htm
欢迎各位大牛、大神莅临QQ群进行交流:575026537
时间: 2024-10-07 20:11:16