Android 6.0的HTTPClient问题与LG G3手机 [英] Android 6.0 HTTPClient issue with LG G3 phone
问题描述
我正在使用DefaultHTTPClient类来创建http请求。
本代码执行()方法适用于所有手机,包括Nexus和Samsung与Android 6.0。 p>
但是当我使用Android 6.0更新的LG手机进行测试时,我收到错误如下所示
Java.lang.ArrayIndexOutOfBoundsException:length = 1; index = 1
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.auth.DigestScheme.isGbaScheme(DigestScheme.java:210)
03- 28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.auth.DigestScheme.processChallenge(DigestScheme.java:176)
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.client.DefaultRequestDirector.processChallenges(DefaultRequestDirector.java:1097)
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache .http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:980)
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.client.DefaultRequestDirector。执行(DefaultRequestDirector.java:490)
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
03-28 17:21:17.040:E / xx_SDK(14035):在org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
03-28 17:21 :17.040:E / xx_SDK(14035):在org.apach e.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
03-28 17:21:17.040:E / xx_SDK(14035):在java.lang.Thread.run(Thread.java :818)
我试图了解什么问题,它谈到Digest认证。
我知道从Android 6.0他们已经删除了Apache Http客户端,现在使用HTTPUrlConnection类
我试图复制从sdk到我的项目lib文件夹的org.apache.http.legacy.jar文件。
但是我仍然面对同一个错误日志。我希望有人可以帮我解决这个问题。
请查看应用程序代码:
HttpParams参数= 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);
sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme(http,PlainSocketFactory.getSocketFactory(),80));
registry.register(new Scheme(https,sf,443));
connectionManager = new SingleClientConnManager(params,registry);
}
catch(异常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(){
@Override
public boolean isRedirectRequested(HttpResponse response,HttpContext context){
}
@Override
public URI getLocationURI(HttpResponse response,HttpContext context)throws ProtocolException {
}
try {
HttpGet httpget = new HttpGet(url);
HttpResponse响应= client.execute(httpget); //这里发生问题
p>进入类似的东西,并有一个修复我试图,我添加到另一个问题
我遇到了类似的问题今天刚刚开始使用适用于Android的HttpClient
- 添加依赖关系
compile'org.apache.httpcompo nents:httpclient-android:4.3.5.1'
to build.gradle。 - 替换
new DefaultHttpClient()
与HttpClientBuilder.create()。build()
您可能需要在代码的其他部分进行其他一些小的重构,但这应该很简单。
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(DigestScheme.java:210)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.auth.DigestScheme.processChallenge(DigestScheme.java:176)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.processChallenges(DefaultRequestDirector.java:1097)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.handleResponse(DefaultRequestDirector.java:980)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:490)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:560)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:492)
03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:470)
03-28 17:21:17.040: E/xx_SDK(14035): at java.lang.Thread.run(Thread.java:818)
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);
sf.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
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() {
@Override
public boolean isRedirectRequested(HttpResponse response, HttpContext context) {
}
@Override
public URI getLocationURI(HttpResponse response, HttpContext context) throws ProtocolException {
}
try {
HttpGet httpget = new HttpGet(url);
HttpResponse response = client.execute(httpget); // issue occur here
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
- Added dependency
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
to build.gradle. - Replace
new DefaultHttpClient()
withHttpClientBuilder.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.
这篇关于Android 6.0的HTTPClient问题与LG G3手机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!