我一直在尝试实现ModernHttpClient,如下所述:http://motzcod.es/post/78863496592/portable-class-libraries-httpclient-so-happy

主要问题是我无法识别Android的OkHttpNetworkHandler或iOS的AFNetworkHandler-我不知道每个使用的引用。对于Android,我具有System.Net.Http,ModernHttpClient和OKHttp。适用于iOS System.Net.Htp和ModernHttpClient。我已经搜索了,但是甚至找不到包含用法的示例代码

public class HttpClientHelper : IHttpClientHelper
{
    private HttpMessageHandler handler;
    public HttpMessageHandler MessageHandler
    {
        get { return handler ?? (handler = new OkHttpNetworkHandler()); }

    }
}


public class HttpClientHelper : IHttpClientHelper
{
    private HttpMessageHandler handler;
    public HttpMessageHandler MessageHandler
    {
        get { return handler ?? (handler = new AFNetworkHandler()); }
    }
}

最佳答案

好吧,看来您不需要任何

将ModernHttpClient作为NuGet包添加到PCL,然后您所需要做的就是

HttpClient client = new HttpClient(new NativeMessageHandler());


有效,并且比HttpClient更快地堆积

关于android - Xamarin使用OKHttpNetworkHandler和AFNetworkHandler的引用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/26542026/

10-08 21:18