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

nav*_*ons 9 android

我升级到最新的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;

}
Run Code Online (Sandbox Code Playgroud)

}

有没有替代品?如果是的话,它应该替换什么?

谢谢

Der*_*ung 28

作为解决方法,将此添加到您的应用程序build.gradle

android {
    useLibrary 'org.apache.http.legacy'
}
Run Code Online (Sandbox Code Playgroud)

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