Can't import org.apache.http.HttpResponse in Android Studio

后端 未结 6 1818
醉梦人生
醉梦人生 2020-12-03 06:53

I want to use these libraries in Android Studio:

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client         


        
6条回答
  •  臣服心动
    2020-12-03 07:31

    HttpClient was deprecated in Android 5.1 and is removed from the Android SDK in Android 6.0. While there is a workaround to continue using HttpClient in Android 6.0 with Android Studio, you really need to move to something else. That "something else" could be:

    • the built-in classic Java HttpUrlConnection
    • Apache's independent packaging of HttpClient for Android
    • OkHttp (my recommendation)
    • AndroidAsync

    Or, depending upon the nature of your HTTP work, you might choose a library that supports higher-order operations (e.g., Retrofit for Web service APIs).

    In a pinch, you could enable the legacy APIs, by having useLibrary 'org.apache.http.legacy' in your android closure in your module's build.gradle file. However, Google has been advising people for years to stop using Android's built-in HttpClient, and so at most, this should be a stop-gap move, while you work on a more permanent shift to another API.

提交回复
热议问题