zoukankan      html  css  js  c++  java
  • The type org.apache.http.HttpResponse cannot be resolved. It is indirectly referenced from required

    Android 6.0(API 23)中,Google已经移除了移除了Apache HttpClient相关的类、HttpResponse类。缺失jar包使用HttpResponse等会报错:

    The type org.apache.http.HttpResponse cannot be resolved. It is indirectly referenced from required 

    1. //获取服务器Json数据  
    2. HttpUtils httpUtils = new HttpUtils();  
    3.   
    4. //发送URL请求  
    5. httpUtils.send(HttpMethod.GET,Myconstants.NEWCENTERURL,new RequestCallBack<String>() {  
    6.       
    7.     @Override//访问数据成功  
    8.     public void onSuccess(ResponseInfo<String> responseInfo) {  
    9.         String jsonData =<u><span style="color:#ff0000;"> responseInfo</span></u>.result;  
    10.         System.out.println(jsonData);  
    11.     }  
    12.   
    13.     @Override//访问数据失败  
    14.     public void onFailure(HttpException error, String msg) {  
    15.         System.out.println("网络请求数据失败"+error);  
    16.     }  
    17. });  
    1. //获取服务器Json数据  
    2. HttpUtils httpUtils = new HttpUtils();  
    3.   
    4. //发送URL请求  
    5. httpUtils.send(HttpMethod.GET,Myconstants.NEWCENTERURL,new RequestCallBack<String>() {  
    6.       
    7.     @Override//访问数据成功  
    8.     public void onSuccess(ResponseInfo<String> responseInfo) {  
    9.         String jsonData =<u><span style="color:#ff0000;"> responseInfo</span></u>.result;  
    10.         System.out.println(jsonData);  
    11.     }  
    12.   
    13.     @Override//访问数据失败  
    14.     public void onFailure(HttpException error, String msg) {  
    15.         System.out.println("网络请求数据失败"+error);  
    16.     }  
    17. });  

    推荐使用HttpUrlConnection,如果要继续使用需要Apache  HttpClient,需要在eclipse下libs里添加org.apache.http.legacy.jar。添加方法如下:

    1>、Eclipse中 在错误原因上点击ctrl+1,选择Configure build path,或者Project->Properties->Java Build Path->Libraries->Add Ecternal JARS->你的SDK目录的

    platformsandroid-23optionalorg.apache.http.legacy.jar->ok


    2>、android studio里在相应的module下的build.gradle中加入:

    android {

    useLibrary 'org.apache.http.legacy'
    }

  • 相关阅读:
    js如何获取当天日期的开始时间和结束时间
    bootstrapTable 刷新数据
    vue全家桶
    JavaScript数组是否存在及是否存在某个元素
    asp.net core 负载均衡集群搭建(centos7+nginx+supervisor+kestrel)
    (转) 将ASP.NET Core应用程序部署至生产环境中(CentOS7)
    mysql 5.7 docker 主从复制架构搭建
    CentOS6.x生产环境下一键安装mono+jexus的脚本,自启动,带服务,版本号自控
    使用 Json.Net 对Json文本进行 增删改查
    C# dynamic 动态创建 json
  • 原文地址:https://www.cnblogs.com/wanghang/p/6299604.html
Copyright © 2011-2022 走看看