Android - 相当于Apache弃用的类

时间:2016-09-19 17:57:19

标签: java android json rest

我想找到下面代码的等价物,因为有些类已被弃用。

try
    {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(url);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();
    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

到目前为止,我已经写了这个,但它不起作用

HttpURLConnection httpUrlConnection = null;
    try
    {
        URL mUrl = new URL(url);
        httpUrlConnection = (HttpURLConnection) mUrl.openConnection();
        httpUrlConnection.setRequestMethod("POST");
        httpUrlConnection.connect();
        is = new BufferedInputStream(httpUrlConnection.getInputStream());
        httpUrlConnection.disconnect();
    }
catch(Exception e)
{
    e.printStackTrace();
}

请求后我收到异常,所以我认为我的请求有问题。

1 个答案:

答案 0 :(得分:0)

您可以使用apache遗留库。在Build.grade顶级文件中放置这些行

import psutil
import matplotlib.pyplot as plt
import matplotlib.animation as animation

a = [i for i in range(1000)]
ram_avaliable = []
fig, ax = plt.subplots()

def update(n):
    ram = psutil.virtual_memory()
    ram_avaliable.append(float(ram[1])/1073741824)
    print (a[n],ram_avaliable[n])
    ax.plot(a[n],ram_avaliable[n])

ani = animation.FuncAnimation(fig,update,interval=100)
plt.show()

这些在app level build.gradle:

buildscript {
    ...
    dependencies {
        classpath 'com.android.tools.build:gradle:1.3.1'
    }
}