微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

android – 包org.apache.http不存在sdk 23

参见英文答案 > Apache HTTP connection with Android 6.0 (Marshmallow)2
升级到最新的sdk版本23.现在我的一些代码不再工作了.
这是我以前得到json的类:
public class Spots_tab1_json {
static String response = null;
public final static int GET = 1;
public final static int POST = 2;

public Spots_tab1_json() {

}
public String makeServiceCall(String url,int method) {
    return this.makeServiceCall(url,method,null);
}
public String makeServiceCall(String url,int method,List<NameValuePair> params) {
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        httpentity httpentity = null;
        HttpResponse httpResponse = null;
        if (method == POST) {
            HttpPost httpPost = new HttpPost(url);
            httpPost.addHeader("Cache-Control","no-cache");
            if (params != null) {
                httpPost.setEntity(new UrlEncodedFormEntity(params,"UTF-8"));
            }
            httpResponse = httpClient.execute(httpPost);
        } else if (method == GET) {
            if (params != null) {
                String paramString = URLEncodedUtils.format(params,"UTF-8");
                url += "?" + paramString;
            }
            HttpGet httpGet = new HttpGet(url);
            httpGet.addHeader("Cache-Control","no-cache");
            httpResponse = httpClient.execute(httpGet);

        }
        httpentity = httpResponse.getEntity();
        response = EntityUtils.toString(httpentity);

    } catch (UnsupportedEncodingException e) {
        e.printstacktrace();
    } catch (ClientProtocolException e) {
        e.printstacktrace();
    } catch (IOException e) {
        e.printstacktrace();
    }

    return response;

}

}

有没有替换?如果是,应该替换什么?

谢谢

解决方法

作为解决方法,将其添加到您的应用程序build.gradle中
android {
    useLibrary 'org.apache.http.legacy'
}

https://developer.android.com/preview/behavior-changes.html#behavior-apache-http-client

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐