Android的德precated Apache模块(HttpClient的,Htt的presponse等) [英] Android deprecated apache module (HttpClient, HttpResponse, etc.)

查看:166
本文介绍了Android的德precated Apache模块(HttpClient的,Htt的presponse等)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Android有去precated因为API级22的Apache模块,所以我的问题是,我怎么用,例如的Htt presponse 从阿帕奇库,而不是Android的SDK?问题是,在the're两个包相同。

Android has deprecated the Apache module since API level 22, so my question is, how do I use, for example HttpResponse from the Apache library, not from Android SDK? The problem is that the're the same in both packages.

但是,例如, HTTPGET 是OK的,因为它被称为 HttpGetHC4 在Apache中。

But, for example, HttpGet is OK, because it's called HttpGetHC4 in Apache.

推荐答案

该方法的HttpClient是pcated德$ P $。现在,您可以使用URLConnection的,你可以在这个例子中看到:

The method HttpClient was deprecated. You can use now the URLConnection as you can see in this example :

private StringBuffer request(String urlString) {
    // TODO Auto-generated method stub

    StringBuffer chaine = new StringBuffer("");
    try{
        URL url = new URL(urlString);
        HttpURLConnection connection = (HttpURLConnection)url.openConnection();
        connection.setRequestProperty("User-Agent", "");
        connection.setRequestMethod("POST");
        connection.setDoInput(true);
        connection.connect();

        InputStream inputStream = connection.getInputStream();

        BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
        String line = "";
        while ((line = rd.readLine()) != null) {
            chaine.append(line);
        }

    } catch (IOException e) {
        // writing exception to log
        e.printStackTrace();
    }

    return chaine;
}

希望这是帮助别人。

Hope this is help someone.

这篇关于Android的德precated Apache模块(HttpClient的,Htt的presponse等)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆