Java Android-相当于Apache弃用类
我正试图找到下面代码的等价物,因为有些类已被弃用Java Android-相当于Apache弃用类,java,android,json,rest,Java,Android,Json,Rest,我正试图找到下面代码的等价物,因为有些类已被弃用 try { DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); HttpResponse httpResponse = httpClient.execute(httpPost); HttpEntity httpEntity = httpRe
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();
}
在请求之后,我得到了一个异常,因此我认为我的请求有问题。您可以使用apache遗留库。在Build.grade顶级文件中放置以下行
buildscript {
...
dependencies {
classpath 'com.android.tools.build:gradle:1.3.1'
}
}
以下是应用程序级build.gradle:
android {
compileSdkVersion 23
buildToolsVersion "23.0.0"
useLibrary 'org.apache.http.legacy'
...
}
httpUrlConnection.disconnect()代码>断开连接后,您认为inputstream会发生什么变化?