1

我正在尝试处理长时间的 HTTPS 请求。我的原始代码使用 ServicePointManager.ServerCertificateValidationCallback,为服务器响应增加了至少 5 秒的延迟,我有一个用 java 编码的类,它真的更快,我正在尝试将其转换为 C#。

这是我的翻译,最后两行没有编译,让我发疯,我怎样才能实例化 ThreadSafeClientConnManager 和 DefaultHttpClient ?

    using Org.Apache.Http.Conn.Schemes;
    using Org.Apache.Http.Conn;
    using Org.Apache.Http.Conn.Ssl;
    using Org.Apache.Http.Params;



    IHttpParams httpParams;
    IClientConnectionManager ccm;

    KeyStore store = KeyStore.GetInstance (KeyStore.DefaultType);
    store.Load (null, null);
    SSLSocketFactory sslSocketFact = new SSLSocketFactory (store);
    sslSocketFact.HostnameVerifier = SSLSocketFactory.AllowAllHostnameVerifier;

    httpParams = new BasicHttpParams();
    HttpProtocolParams.SetVersion(httpParams, Org.Apache.Http.HttpVersion.Http11);
    HttpProtocolParams.SetContentCharset(httpParams, "UTF-8");

    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.Register(new Scheme("http", PlainSocketFactory.SocketFactory, 80));
    schemeRegistry.Register(new Scheme("https", sslSocketFact, 443));

    new ThreadSafeClientConnManager(httpParams, schemeRegistry);
    HttpClient client =  new DefaultHttpClient(ccm, httpParams);
4

0 回答 0