在Android 2.2上使用ssl时遇到一些困难 我的自定义Http客户端for ssl在早期版本和旧版本的Android上工作, 但在2.2 https请求不运行所有。 这是我的代码:
public class SSLHttpClient extends DefaultHttpClient {
final Context context;
public SSLHttpClient(Context context,HttpParams params) {
super(params);
this.context = context;
}
@Override
protected ClientConnectionManager createClientConnectionManager() {
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", PlainSocketFactory
.getSocketFactory(), 80));
registry.register(new Scheme("https", newSslSocketFactory(), 443));
return new SingleClientConnManager(getParams(), registry);
}
private SSLSocketFactory newSslSocketFactory() {
try {
SSLSocketFactory sf = new SSLSocketFactory(keyStore,"",trustStore);
//---------some code--------------------------------------
return sf;
} catch (Exception e) {
throw new AssertionError(e);
}
}
}
我发现了一些类似的文章,但他们没有解决我的问题。 也许有人面临这样的问题。 提前谢谢......
答案 0 :(得分:0)
这样的配置对我有用(无需添加80端口即可测试):
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
sslSocketFactory.setHostnameVerifier(SSLSocketFactory.BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
registry.register(new Scheme("https", sslSocketFactory, 443));
SingleClientConnManager manager = new SingleClientConnManager(params, registry);