Android LG G3 的 6.0 HTTPClient 问题 phone
Android 6.0 HTTPClient issue with LG G3 phone
您好,我正在使用 DefaultHTTPClient class 创建 http 请求。
当前代码 execute() 方法适用于所有手机,包括 Android 6.0 的 Nexus 和三星。
但是当我在装有 Android 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.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 class
我试图将 "org.apache.http.legacy.jar" 文件从 sdk 复制到我的项目 lib 文件夹。
但我仍然面临同样的错误日志。我希望有人可以帮助我解决这个问题。
请按原样找到应用程序代码:
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
运行 变成了类似的东西并且有一个修复我正在尝试添加到 another question
我 运行 今天遇到了类似的问题,刚开始使用 HttpClient for Android
- 已将依赖项
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
添加到 build.gradle。
- 将
new DefaultHttpClient()
替换为HttpClientBuilder.create().build()
您可能需要在代码的其他部分进行一些其他小的重构,但这应该非常简单。
试一试,我在 MotoX 运行 6.0.1 上遇到了类似的问题,但这似乎对我有用。
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;
}
}
也将其粘贴到 gradle 下的 dependencies
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'
您好,我正在使用 DefaultHTTPClient class 创建 http 请求。
当前代码 execute() 方法适用于所有手机,包括 Android 6.0 的 Nexus 和三星。
但是当我在装有 Android 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.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 class
我试图将 "org.apache.http.legacy.jar" 文件从 sdk 复制到我的项目 lib 文件夹。
但我仍然面临同样的错误日志。我希望有人可以帮助我解决这个问题。
请按原样找到应用程序代码:
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
运行 变成了类似的东西并且有一个修复我正在尝试添加到 another question
我 运行 今天遇到了类似的问题,刚开始使用 HttpClient for Android
- 已将依赖项
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
添加到 build.gradle。 - 将
new DefaultHttpClient()
替换为HttpClientBuilder.create().build()
您可能需要在代码的其他部分进行一些其他小的重构,但这应该非常简单。
试一试,我在 MotoX 运行 6.0.1 上遇到了类似的问题,但这似乎对我有用。
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;
}
}
也将其粘贴到 gradle 下的 dependencies
compile group: 'org.apache.httpcomponents' , name: 'httpclient-android' , version: '4.3.5.1'