Sunil Sunil - 2 years ago 225
Java Question

Android 6.0 HTTPClient issue with LG G3 phone

Hi I am using DefaultHTTPClient class to create http request.

The currrent code execute() method works on all phones including Nexus and Samsung with Android 6.0.

But when i tested on LG phones with Android 6.0 update, i am getting error as shown below

Java.lang.ArrayIndexOutOfBoundsException: length=1; index=1
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.auth.DigestScheme.isGbaScheme(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.auth.DigestScheme.processChallenge(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.processChallenges(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.execute(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(
03-28 17:21:17.040: E/xx_SDK(14035): at

I tried to understand what issue, It talks about Digest authentication.

I know from Android 6.0 they have removed Apache Http client and now uses HTTPUrlConnection class

I tried to copy the "org.apache.http.legacy.jar" file from sdk to my project lib folder.

But still i face the same error log. I hope someone can help me to get wor around with this issue.

Kindly find the application code as it is :

HttpParams params = new BasicHttpParams();
ClientConnectionManager connectionManager = null;
try {
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", sf, 443));
connectionManager = new SingleClientConnManager(params, registry);
catch (Exception e)
Log.e(TAG, Log.getStackTraceString(e));

ConnManagerParams.setTimeout(params, mTimeOut);
HttpConnectionParams.setSoTimeout(params, mTimeOut);
HttpConnectionParams.setConnectionTimeout(params, mTimeOut);
HttpConnectionParams.setTcpNoDelay(params, true);

DefaultHttpClient client = new DefaultHttpClient(connectionManager, params);

client.getCredentialsProvider().setCredentials(new AuthScope(host,port),
new UsernamePasswordCredentials(userID,passowrd));

client.setRedirectHandler(new RedirectHandler() {
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {

try {
HttpGet httpget = new HttpGet(url);
HttpResponse response = client.execute(httpget); // issue occur here

Answer Source

Ran into something similar and had a fix I'm trying that I added to another question

I ran into a similar issue today and just started using HttpClient for Android

  1. Added dependency compile 'org.apache.httpcomponents:httpclient-android:' to build.gradle.
  2. Replace new DefaultHttpClient() with HttpClientBuilder.create().build()

There are probably some other minor refactors you might need to make in other portions of the code, but that should be pretty straight forward.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download