开篇报错注意:本教程是基于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. VS2010 ReportViewer导出文件下载保存不能识别文件类型

    今天测试项目时,突然发现导出报表下载保存的保存,不能识别文件的类型,文件名称为:.xls[3] 检查代码发现在指定报表路径时多了一个方法: ReportViewer1.LocalReport.Load ...

  2. VS2013以管理员身份使用

    Win8系统: 1.将C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe改为以管理员身份运行. 2.将 ...

  3. struts 2 --SEVERE: Could not find action or result

    SEVERE: Could not find action or result There is no Action mapped for namespace / and action name . ...

  4. js 计算某年某周日期范围

    <HTML><HEAD><script type="text/javascript"> //目前只判断了4位有效输入的年份,//日期输出格式已处 ...

  5. 一个经试用效果非常不错的数据库连接池--JAVA

    前言: 虽说现在许多企业级的应用服务器均自己带有数据库连接池功能,就连 Tomcat 也支持了这种功能.然而在许多时候,我们还是要使用数据库连接池,如:访问数据库的 Java 桌面应用程序等.这个数据 ...

  6. debug模式启动provider

    debug 模式启动 1 sts中的配置见图片 2 centos中 ./knowledge-start.sh debug win系统ip ./knowledge-start.sh debug 192. ...

  7. Android开源框架之SwipeListView导入及模拟QQ侧滑

    SwipeListView是Github上的一个开源框架,地址:https://github.com/47deg/android-swipelistview SwipeListView was bor ...

  8. CloudStack核心类ApiServlet、ApiServer、ApiDispatcher、GenericDaoBase源码分析

    ApiServlet 首先从整体上看下ApiServlet,Outline视图如下, 一.注意@Inject依赖的是javax.inject.jar,它和spring的@Autowired的区别在于使 ...

  9. C3P0连接池详细配置

    C3P0连接池详细配置 转自http://msq.javaeye.com/blog/60387 <c3p0-config> <default-config> <!--当连 ...

  10. bzoj3721 [PA2014 Final] Bazarek

    Description 有n件商品,选出其中的k个,要求它们的总价为奇数,求最大可能的总价. Input 第一行一个整数n(1<=n<=1000000),表示商品数量.接下来一行有n个整数 ...