2016-09-19 2 views
-1

いくつかのクラスは廃止予定ですので、以下のコードに相当するものを見つけようとしています。Android - Apacheの廃止されたクラスと同等です

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(); 
} 

を動作しません。

+0

を 'httpUrlConnection.disconnect();'あなたは後に、あなたの入力ストリームに何が起こるかだと思いますか切断する? – njzk2

答えて

0

apache legacy libraryを使用できます。 Build.gradeトップレベルファイルでは、これらの行のアプリレベルのbuild.gradleで

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

そして、これら入れる:

android { 
    compileSdkVersion 23 
    buildToolsVersion "23.0.0" 
    useLibrary 'org.apache.http.legacy' 
    ... 
} 
関連する問題