开篇报错注意:本教程是基于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. lambda语法

    (参数列表) => 表达式或者语句块 s => (s.IndexOf("a") > -1 其中:参数个数:可以有多个参数,一个参数,或者无参数.表达式或者语句块: ...

  2. hdu4497 正整数唯一分解定理应用

    C - (例题)整数分解,计数 Crawling in process... Crawling failed Time Limit:1000MS     Memory Limit:65535KB    ...

  3. Qt添加窗口背景图片、Label图片显示、、Label文字显示

    一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...

  4. 美化xterm

    很多软件调试时,会打开xterm,不过很难看,字体.背景等等都不好看,网上找到了一个不错的xterm的配置文件 !look and feel xterm.termName: xterm-256colo ...

  5. ashx中session的使用

    在平常的页面上是用是很容易就的到request,response对像,从而对其进行一些操作,但在ashx(一般处理程序)中却是有一点的不同, 在ashx你无法正常的使用session,即 contex ...

  6. php环境安装及搭建

    最近由于项目需要 转战 PHP .  在做了差不多两年java后 说实话看php代码还是有些难受的. 毕竟不习惯.废话不说 先说一下 PHP环境的部署等等,也就是最近几天学习的心得吧.方便以后参考. ...

  7. CoreData (三)备

    NSFetchedResultsController 什么是NSFetchedResultsController NSFetchedResultsController是一个让人爱恨交加的一个类.如果使 ...

  8. abiword rtf 解析

    目前为止,代码跟进,知道是这个地方进行文件解析的 T_Error IE_Imp_RTF::importFile(const char * szFilename)

  9. 开心菜鸟系列学习笔记-------javascript(3)

    一.原型链:     1)Object 是一个属性的集合,并且都拥有一个单独的原型对象.,这个原型对象object可以是一个object或者null值 2)不过一般来说,我们会使用__内部属性名__下 ...

  10. LeetCode_Pascal's Triangle

    Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5, Retu ...