一部のプロジェクトでは、同様SocketFactory
のX509TrustManager
実装を使用しています。これらのクラスを実装にバインドするために、基本的に行う必要がHttpClient
あるのは、クライアント/サーバー通信に使用される(使用しているものであると想定して)クラスを接続することだけです。
HttpClient
通常、前述のファクトリとトラストマネージャを使用してを作成する方法があります。これはややこのように見え、インラインコメントに示されているリンクに大まかに基づいています。
protected HttpClient constructClient() {
HttpParams params = new BasicHttpParams();
params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
// use the debug proxy to view internet traffic on the host computer
if (ABCApplication.isDebuggingProxy()) params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(ABCConstants.DEBUG_PROXY_HOST, ABCConstants.DEBUG_PROXY_PORT, "http"));
// ignore ssl certification (due to signed authority not appearing on android list of permitted authorities)
// see: http://blog.antoine.li/2010/10/22/android-trusting-ssl-certificates/
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("http", new PlainSocketFactory(), 80));
registry.register(new Scheme("https", new FakeSocketFactory(), 443));
ClientConnectionManager cm = new SingleClientConnManager(params, registry);
return new DefaultHttpClient(cm, params);
}
それがあなたの実装に役立つことを願っています。