嗨,我正在使用defaulthttpclient类创建http请求。
current code execute()方法适用于所有手机,包括nexus和三星android 6.0。
但是当我在使用android6.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)
我试图理解什么问题,它涉及到摘要认证。
我知道android6.0已经删除了apachehttp客户端,现在使用httpurlconnection类
我试图将“org.apache.http.legacy.jar”文件从sdk复制到我的project 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
2条答案
按热度按时间erhoui1w1#
遇到了类似的问题,我正在尝试一个修正,我在另一个问题中添加了这个修正
我今天遇到了一个类似的问题,刚开始使用httpclient for android
添加了依赖项
compile 'org.apache.httpcomponents:httpclient-android:4.3.5.1'
去建造grad尔。替换
new DefaultHttpClient()
与HttpClientBuilder.create().build()
您可能需要在代码的其他部分进行其他一些小的重构,但这应该是非常直接的。p8ekf7hl2#
试一试,我在运行6.0.1的motox上也遇到过类似的问题,但这似乎对我很有用。
把这个放在gradle的dependencies下