I have a simple class written in Android Studio:
package com.mysite.myapp; import org.apache.http.client.HttpClient; public class Whatever { public void headBangingAgainstTheWallExample () { HttpClient client = new DefaultHttpClient(); } }
and from this I get the following compile time error:
Cannot resolve symbol HttpClient
Isn't HttpClient
included in the Android Studio SDK? Even if it is not, I added it to my Gradle build like this:
dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) compile 'com.android.support:appcompat-v7:23.0.0' compile 'org.apache.httpcomponents:httpclient:4.5' }
With or without the last compile line, the error is the same. What am I missing?
An HTTP Client. An HttpClient can be used to send requests and retrieve their responses. An HttpClient is created through a builder . The builder can be used to configure per-client state, like: the preferred protocol version ( HTTP/1.1 or HTTP/2 ), whether to follow redirects, a proxy, an authenticator, etc.
The Apache HttpClient library allows to handling HTTP requests. To use this library add a dependency to your Maven or Gradle build file. You find the latest version here: https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient. You retrieve and send data via the HttpClient class.
HttpClient
is not supported any more in sdk 23. You have to use URLConnection
or downgrade to sdk 22 (compile 'com.android.support:appcompat-v7:22.2.0'
)
If you need sdk 23, add this to your gradle:
android { useLibrary 'org.apache.http.legacy' }
You also may try to download and include HttpClient jar directly into your project or use OkHttp instead
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With