您可以使用以下方法。
SSLContext首先,在创建对象时保留对对象的引用。
SSLContext sslContext=SSLContext.getDefault();
sslContext.getServerSocketFactory().createServerSocket(1234).accept();
然后,当您要加载新的时,您可以使用相应的TrustManagerTrustManager再次调用该方法,如下所示。init()
TrustManager trustManagers[] = // load trust managers here.
sslContext.init(null,trustManagers,null);
在这里,该init()方法采用 3 个参数KeyManager[],TrustManager[]和SecureRandom。如果您通过null其中任何一个,SSLContext将加载默认的密钥管理器和信任管理器。由于您只想加载信任管理器,因此您必须将新的传递TrustManager[]给它。
由于您没有更改对SSLContext对象的引用,因此这不会破坏您的流程或不会影响您现有SSLIOSession的 s。