Java LG G3手机出现Android 6.0 HTTPClient问题
您好,我正在使用DefaultHTTPClient类创建http请求 current code execute()方法适用于包括Nexus和Android 6.0的三星在内的所有手机 但当我在使用安卓6.0更新的LG手机上进行测试时,我发现如下所示的错误Java LG G3手机出现Android 6.0 HTTPClient问题,java,android,eclipse,apache-httpclient-4.x,android-6.0-marshmallow,Java,Android,Eclipse,Apache Httpclient 4.x,Android 6.0 Marshmallow,您好,我正在使用DefaultHTTPClient类创建http请求 current code execute()方法适用于包括Nexus和Android 6.0的三星在内的所有手机 但当我在使用安卓6.0更新的LG手机上进行测试时,我发现如下所示的错误 Java.lang.ArrayIndexOutOfBoundsException: length=1; index=1 03-28 17:21:17.040: E/xx_SDK(14035): at org.apache.http.impl
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)
我试图理解什么问题,它涉及摘要身份验证
我从Android 6.0知道他们已经删除了Apache Http客户端,现在使用的是HTTPUrlConnection类
我试图将“org.apache.http.legacy.jar”文件从sdk复制到我的项目库文件夹中
但我仍然面临同样的错误日志。我希望有人能帮助我解决这个问题
请按原样查找申请代码:
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
遇到了类似的情况,我正在尝试添加一个修复
我今天遇到了类似的问题,刚开始使用
compile'org.apache.httpcomponents:httpclient-android:4.3.5.1'
HttpClientBuilder.create().build()
您可能需要在代码的其他部分进行其他一些小的重构,但这应该是非常直截了当的。试一试,我在运行6.0.1的MotoX上也遇到过类似的问题,但这似乎对我有效
protected static final int HTTP_JSON_TIMEOUT_CONNECTION = 20000;
protected static final int HTTP_JSON_TIMEOUT_SOCKET = 20000;
CloseableHttpResponse response = null;
try {
UserPrefs.clearCacheFolder(mContext.getCacheDir());
CloseableHttpClient httpClient = getApacheHttpClient();
HttpPost httpPost = getHttpPost( invocation);
response = httpClient.execute(httpPost);
}catch (Exception e){
e.printStackTrace();
}
protected CloseableHttpClient getApacheHttpClient(){
try {
// Socket config
SocketConfig socketConfig = SocketConfig.custom()
.setSoTimeout(HTTP_JSON_TIMEOUT_SOCKET)
.build();
// Auth
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(new AuthScope(URL, PORT, null, "Digest"),
new UsernamePasswordCredentials(USERNAME,DIGEST_PASSWORD));
// Build HttpClient
return HttpClients.custom()
.setDefaultSocketConfig(socketConfig)
.setDefaultCredentialsProvider(credentialsProvider)
.build();
}catch (Exception e) {
Log.i("ApacheHttpClientHelper", "ERROR >> "+e.getMessage());
return null;
}
}
也将其粘贴到“依赖项”下的渐变中
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
我按照安卓6.0规范使用了这个库。useLibrary“org.apache.http.legacy.jar”。我看到的是它发送http请求。服务器用401代码响应,我们用摘要身份验证再次发送。如果您看到错误日志,我觉得摘要参数有些问题。同时你能告诉我如何使用你的新代码吗。我无法理解如何更改DefaultClient。你的第二点不清楚,我也在使用传统的jar,但仍然只在LG G5和LG G3上出现错误。我没有看到示例代码,所以我假设您在某个地方使用apache库中的
DefaultHttpClient
。如果添加新的依赖项,则需要在发出请求之前更新使用DefaultHttpClient
以使用HttpClientBuilder
的代码。这将使用httpclient android中的新代码,并且应该正确处理摘要参数。非常感谢您的评论。我真的很高兴看到你的支持。这对我来说是一个非常关键的问题。根据你的评论,我已经更新了我的应用程序代码。现在您可以看到上面的代码。请支持我如何根据HttpClientBuilder更改此代码。我能够使用您给我的答案和提到的库纠正lg电话错误。一切正常,直到我看到HTTPS连接不起作用。使用HTTPS时,我无法使应用程序正常工作。因此,我为它添加了一个新问题。请帮助我使用新库纠正ssl问题