org.apache.http这个包是几年前的了,按照现在版本更迭的速度,估计过几年都没人能记起这个了吧。
先说问题
项目中类报红,提示找不到该类。
import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.NameValuePair; import org.apache.http.client.HttpClient; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPut; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.ByteArrayEntity; import org.apache.http.message.BasicNameValuePair; import org.apache.http.params.HttpConnectionParams; import org.apache.http.params.HttpParams;报错:
错误: 程序包org.apache.http.impl.cookie不存在
import org.apache.http.impl.cookie.DateUtils;
错误: 程序包org.apache.http.client不存在
import org.apache.http.client.HttpClient;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpDelete;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpGet;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpPost;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpPut;
错误: 程序包org.apache.http.client.methods不存在
import org.apache.http.client.methods.HttpUriRequest;
错误: 找不到符号
protected final HttpClient mClient;
错误: 找不到符号
public HttpClientStack(HttpClient client) {
^
符号: 类 HttpClient
位置: 类 HttpClientStack
错误: 找不到符号
private static void addHeaders(HttpUriRequest httpRequest, Map<String, String> headers) {
^
符号: 类 HttpUriRequest
位置: 类 HttpClientStack
解决方法:
在项目build.gradle中
在buildToolsVersion下边
defaultConfig上边
添加如下代码
useLibrary 'org.apache.http.legacy'
发表评论: