开篇报错注意:本教程是基于xUtils-2.6.14.jar版本实现的

由于studio中6.0以后安卓取消了httpclient,而xutils则基于httpclient开发的,所以现在无法使用,将会有以下的错误

Error:(55, 30) 错误: 无法访问HttpRequestBase

找不到org.apache.http.client.methods.HttpRequestBase的类文件
Error:(85, 30) 错误: 无法访问HttpEntityEnclosingRequest
找不到org.apache.http.HttpEntityEnclosingRequest的类文件
Error:Execution failed for task ':app:compileDebugJavaWithJavac'.
> Compilation failed; see the compiler error output for details.
2 个错误
:app:compileDebugJavaWithJavac FAILED

解决方案:在使用xutils的modle的build.gradle的  android的下添加

这句话:useLibrary 'org.apache.http.legacy'    即可解决

HttpUtilsGet方式

     public void xUtils_HttpUtilsGetString(String url) {
//HttpUtils实例化对象
HttpUtils http = new HttpUtils();
/*
*发送请求send(HttpMethod method, String url, RequestCallBack<T> callBack)
* method请求方式
* url请求地址
*RequestCallBack <String>请求完后的回调监听String是请求完后你想让他返回什么类型的
*/
http.send(HttpRequest.HttpMethod.GET, url,
new RequestCallBack<String>() {
@Override
public void onLoading(long total, long current, boolean isUploading) {
}
@Override
public void onSuccess(ResponseInfo<String> responseInfo) {
tvShow.setText(responseInfo.result);
}
@Override
public void onStart() {
}
@Override
public void onFailure(HttpException error, String msg) {
}
});
}

HttpUtilsPost方式

public void xUtils_HttpUtilsPostString(String url) {
//RequestParams对象是用来存放请求参数的
RequestParams params = new RequestParams();
//例如:"http://www.sciencenet.cn/xml/iphoneinterface.aspx?type=news&nums=20"
    //params.addHeader("name","value”);//如果需要添加特殊的请求头可以使用这个
       params.addBodyParameter("type", "news");//添加请求参数
params.addBodyParameter("nums", ""); //添加请求参数
    //HttpUtils实例化对象 HttpUtils http = new HttpUtils(); 
    //发送请求/** *send(HttpMethod method, String url, RequestParams params, RequestCallBack<T> callBack) * method请求方法,url请求路径,params请求需要携带的参数,RequestCallBack成功后的回调方法 */
    http.send(HttpRequest.HttpMethod.POST, url, params, new RequestCallBack<String>() {
     @Override
    publicvoid onSuccess(ResponseInfo<String> responseInfo) {
    Log.i(TAG, "xUtils_HttpUtilsPostString...onSuccess: "+responseInfo.result);
      tvShow.setText("xUtils_HttpUtilsPostString"+responseInfo.result);
     }
    @Override
    publicvoid onFailure(HttpException e, String s) {
    Toast.makeText(MainActivity.this, "xUtils_HttpUtilsPostString加载失败", Toast.LENGTH_SHORT).show();
    Log.e(TAG, "xUtils_HttpUtilsPostString....onFailure: "+e );
    }});
}
BitmapUtils的简单使用
     public void xUtilsLoadBitmap(String url) {
//获得BitmapUtils的对象
BitmapUtils bitmapUtils = new BitmapUtils(this);
bitmapUtils.configDefaultLoadingImage(R.mipmap.ic_launcher);//默认背景图片
bitmapUtils.configDefaultLoadFailedImage(R.mipmap.ic_launcher);//加载失败图片
bitmapUtils.configDefaultBitmapConfig(Bitmap.Config.RGB_565);//设置图片压缩类型
// 加载网络图片
bitmapUtils.display(image, url);
// 加载本地图片(路径以/开头, 绝对路径)
//bitmapUtils.display(testImageView, "/sdcard/test.jpg");
// 加载assets中的图片(路径以assets开头)
// bitmapUtils.display(testImageView, "assets/img/wallpaper.jpg");
// 使用ListView等容器展示图片时可通过PauseOnScrollListener控制滑动和快速滑动过程中时候暂停加载图片
// listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true));
// listView.setOnScrollListener(new PauseOnScrollListener(bitmapUtils, false, true, customListener));
}

xutils的HttpUtils,Post和Get基本使用,以及BitmapUtils的简单使用的更多相关文章

  1. 3. Android框架和工具之 xUtils(HttpUtils)

    1. HttpUtils 作用: 支持同步,异步方式的请求: 支持大文件上传,上传大文件不会oom: 支持GET,POST,PUT,MOVE,COPY,DELETE,HEAD请求: 下载支持301/3 ...

  2. XUtils骨架HttpUtils采用Get总是返回请求解决问题的相同信息

    如需转载请注明出处:http://blog.csdn.net/itas109 版本号:Xutils 2014年11月11日 下载地址:https://github.com/wyouflf/xUtils ...

  3. Android开源项目xUtils HttpUtils模块分析(转)

    xUtils是github上的一个Android开源工具项目,其中HttpUtils模块是处理网络连接部分,刚好最近想整理下Android网络编程知识,今天学习下xUtils中HttpUtils. x ...

  4. Volley-XUtils-OkHttp三种方式实现单张多张图片上传

    OkHttp可以作为Volley底层传输协议,速度更快,传大量图片建议使用.OkHttp更多功能请看OkHttp的使用 xUtils 支持大文件上传,更全面的http请求协议支持(10种谓词),拥有更 ...

  5. apache.http.MalformedChunkCodingException: Chunked stream ended unexpectedly

    产生的原因,应该是服务器返回的数据不是规范的格式 .我使用的xutils的httpUtils来实现网络通信的,关于读取数据是在 StringDownloadHandler类中源代码 inputStre ...

  6. Android之网络图片加载的5种基本方式

    学了这么久,最近有空把自己用到过的网络加载图片的方式总结了出来,与大家共享,希望对你们有帮助. 此博客包含Android 5种基本的加载网络图片方式,包括普通加载HttpURLConnection.H ...

  7. XUtils框架中HttpUtils使用Get请求时总是返回相同信息的问题解决,xutilshttputils

    如需转载请标明出处:http://blog.csdn.net/itas109 版本:Xutils 2014年11月11日 下载地址:https://github.com/wyouflf/xUtils ...

  8. XUtils开源框架的使用(HttpUtils支持多线程断点续传)

    XUtils项目下载地址:https://github.com/wyouflf/xUtils XUtils中包含的四大模块: 1.DbUtils模块 2.ViewUtils模块 3.HttpUtils ...

  9. [Android] 开源框架 xUtils HttpUtils 代理设置 (Temporary Redirect错误)

    今天简单学习了一下xUtils的使用 https://github.com/wyouflf/xUtils 其中用到HttpUtils模块时,发现总是出现Temporary Redirect 错误. 查 ...

随机推荐

  1. AndroidAnnotations框架配置

    如今Android Studio的普及,Android开发基本要舍弃Eclipse了,最近使用AndroidAnnotations 注解框架的时候,找了些资料慢慢整出来了,在这给大家简单分享一下: 首 ...

  2. EMCA常用命令 【weber整理必出精品】

    EMCA常用命令 创建一个EM资料库 emca -repos create 重建一个EM资料库 emca -repos recreate 删除一个EM资料库 emca -repos drop 配置数据 ...

  3. NSArray使用小结

    http://blog.csdn.net/ms2146/article/details/8654263

  4. vc中调用Com组件的方法详解

    vc中调用Com组件的方法详解 转载自:网络,来源未知,如有知晓者请告知我.需求:1.创建myCom.dll,该COM只有一个组件,两个接口:   IGetRes--方法Hello(),   IGet ...

  5. 怎么判断PC端浏览器内核

    browser = {             /**              * @property {boolean} ie 检测当前浏览器是否为IE              */       ...

  6. GDB调试一

    http://blog.csdn.net/haoel/article/details/2881 GDB主要调试的是C/C++的程序.要调试C/C++的程序,首先在编译时,我们必须要把调试信息加到可执行 ...

  7. PHP学习路上的一点心得

    继学些了java后,接触php的项目后发现 php真的也是很强大的一门语言,这只是一篇回想,想到什么就写什么把,大家随便看看. 1.php其实无需等待,一般的改完代码后直接刷新页面即可,不需要像jav ...

  8. CC2530定时器1的模模式中断

    CC2530定时器1的模模式中断void timer1SInit(void){ T1CCTL0 = 0; T1CTL &= ~0x0F; //clear register T1CTL |= 0 ...

  9. java生产者消费者并发协作

    随着职务转变,代码荒废很久了,很多时间都是在沟通需求,作为一名技术员,不写代码就感觉是在自废武功,慢慢颓废了很多,今天重新回顾了下JAVA线程知识,基础知识就不梳理了,网上也很多,主要关键几个状态位( ...

  10. nginx的url重写[rewrite规则和参考]

    本日志内容来自互联网和平日使用经验,整理一下方便日后参考. Nginx Rewrite 相关指令有 if.rewrite.set.return 等. if 的语法 应用于 server 和 locat ...