2015-08-30 33 views
9

Aktualizuję do najnowszej wersji sdk 23. Teraz niektóre kody nie działają. jest to klasa miałem przed uzyskania json:android - pakiet org.apache.http nie istnieje sdk 23

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; 

} 

}

jest jakiś zamiennik? jeśli tak, to co należy zastąpić?

dzięki

Odpowiedz

27

jako obejście, dodać do swojej build.gradle aplikacji

android { 
    useLibrary 'org.apache.http.legacy' 
} 

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

+0

dzięki za odpowiedź, ale starałem się dodać ten kod do obu gradles ale to nie robi praca. daje mi nieodnalezioną metodę DSL Gradle: błąd "useLibrary()". – navidjons

+1

http://stackoverflow.com/questions/30856785/how-to-add-apache-http-api-legacy-as-compile-time-dependency-to-build-grade sprawdź tutaj, domyślam się, że musisz zaktualizować zależność –

Powiązane problemy