安卓:计划“HTTP”而不是ICS 4.0.4注册瓦特/代理 [英] Android: Scheme 'http' not registered on ICS 4.0.4 w/ proxy

查看:225
本文介绍了安卓:计划“HTTP”而不是ICS 4.0.4注册瓦特/代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用HttpClient的HTTPS请求,它一直很好,直到如今。升级到ICS后,一些用户报告的问题连接上3G连接。

I'm using HttpClient for HTTPS requests, which has worked fine up until now. After upgrading to ICS, some users are reporting problems connecting on 3G connections.

编辑:他们中的大多数似乎是使用代理,我可以用T-Mobile的SIM卡使用其代理本地重现此

Most of them seem to be using a proxy, and I can reproduce this locally with a T-Mobile SIM using their proxy.

日志有这样的堆栈跟踪:

The logs have this stack trace:

java.lang.IllegalStateException: Scheme 'http' not registered.
org.apache.http.conn.scheme.SchemeRegistry.getScheme(SchemeRegistry.java:80)
org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:126)
org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)

我们的终点是仅HTTPS,所以我们不注册我们的SchemeRegistry的目的HTTP端点。没有任何地方(据我所知),我们重定向到HTTP。

Our endpoint is HTTPS only, so we do not register a HTTP endpoint in our SchemeRegistry on purpose. There isn't anywhere (AFAIK) where we redirect to HTTP.

下面是code,设置了HttpClient的为HTTPS客户端:

Here is the code that sets up the HttpClient for the HTTPS client:

    DefaultHttpClient ret = null;

    // sets up parameters
    HttpParams params = new BasicHttpParams();
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf-8");
    params.setBooleanParameter("http.protocol.expect-continue", false);

    HttpConnectionParams.setConnectionTimeout(params, DEFAULT_CONN_TIMEOUT_MSEC);
    HttpConnectionParams.setSoTimeout(params, timeoutMsec);
    HttpConnectionParams.setStaleCheckingEnabled(params, true);

    SchemeRegistry registry = new SchemeRegistry();
    final SocketFactory sslSocketFactory = getPreferredSSLSocketFactory();
    registry.register(new Scheme("https", sslSocketFactory, 443));

    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager(params, registry);
    ret = new DefaultHttpClient(manager, params);
    // for preemptive authentication
    // http://dlinsin.blogspot.com/2009/08/http-basic-authentication-with-android.html
    ret.addRequestInterceptor(preemptiveAuth, 0);
    ret.setCookieStore(communalCookieJar);

    SimpleCredentialsProvider credProvider = new SimpleCredentialsProvider(getAccountPreferences());
    ret.setCredentialsProvider(credProvider);

    return ret;

请注意:我们在多个线程之间共享该HttpClient的实例

Note: We share this HttpClient instance among multiple threads.

推荐答案

这个问题似乎是,一些运营商均与4.0.4更新推无效的代理定义。这打破了HTTPS,但HTTP工作正常(谷歌播放不工作,例如)。

The issue seemed to be that some carriers were pushing invalid proxy definitions with the 4.0.4 update. This broke HTTPS but HTTP worked properly (Google Play didn't work, for instance).

一个可能的修复(除了固定的无效的代理项)是捕捉IllegalStateException异常进行HttpClient的请求,并设置一个标志时。这code将绕过任何代理:

One possible fix (besides fixing the invalid proxy entry) is to catch IllegalStateException when performing HttpClient requests and set a flag. This code will bypass any proxies:

    hc = new DefaultHttpClient(manager, params);
    if (BYPASS_PROXY)
        hc.setRoutePlanner(new DefaultHttpRoutePlanner(registry));

这篇关于安卓:计划“HTTP”而不是ICS 4.0.4注册瓦特/代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆