如何访问Xamarin中的Org.Apache.Http.Impl.client.DefaultHttpclient?

时间:2013-09-04 17:29:59

标签: c# android https xamarin

我正在尝试处理长时间的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);

0 个答案:

没有答案