我正在學習使用Lynda 2014教程的Android寧靜Web服務。該代碼使用此httpManager類:無法導入AndroidHttpClient;
import android.net.http.AndroidHttpClient;
public class HttpManager {
public static String getData(String uri) {
HttpClient client = AndroidHttpClient.AndroidHttpClient.netInstance("AndroidAgaent");
HttpGet request = New HttpGet(uri);
HttpResponse response;
try {
response = client.execute(request);
return EntiyUtils.toString(response.getEntinity());
} catch (Exception e) {
e.printStackTrace();
return null;
} finally {
client.close();
}
}
}
不過,Android工作室說:
無法解析符號 'AndroidHttpClient'
我設置minSdkVersion 8
,但還是沒能解決的問題。
我想知道如何解決這個問題,或者如果類已經丟棄,如何用開箱即用的當前類替換代碼?
https://stackoverflow.com/questions/32949626/org-apache-http-entity-fileentity-is-deprecated-in-android-6-marshmallow – CommonsWare
感謝CommonsWare的提示。那麼okhttp仍然是你的個人建議? – Karlom
如果您將自己限制爲「當前支持開箱即用的類」,則您唯一的選擇是「HttpURLConnection」。如果您願意使用圖書館,我推薦使用HTTP系列的HTTP庫:OkHttp3(普通HTTP),Retrofit(Web服務)和Picasso(圖像)。 – CommonsWare