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. });  
		//获取服务器Json数据
		HttpUtils httpUtils = new HttpUtils();
		
		//发送URL请求
		httpUtils.send(HttpMethod.GET,Myconstants.NEWCENTERURL,new RequestCallBack<String>() {
			
			@Override//访问数据成功
			public void onSuccess(ResponseInfo<String> responseInfo) {
				String jsonData =<u><span style="color:#ff0000;"> responseInfo</span></u>.result;
				System.out.println(jsonData);
			}

			@Override//访问数据失败
			public void onFailure(HttpException error, String msg) {
				System.out.println("网络请求数据失败"+error);
			}
		});

推荐使用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目录的

\platforms\android-23\optional\org.apache.http.legacy.jar->ok


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

android {

useLibrary 'org.apache.http.legacy'
}


转自: http://blog.csdn.net/u010194538/article/details/51218394
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值