Xamarin.forms Xamarin.Net标准2.0的ModernHttpClient的替代选项

Xamarin.forms Xamarin.Net标准2.0的ModernHttpClient的替代选项,xamarin.forms,.net-standard-2.0,Xamarin.forms,.net Standard 2.0,我有一个老项目,它是在Xamarin.FormV2.5。不推荐使用的是PCL项目。我正在尝试升级,但forModernHttpClient无法正常工作。这表明DLL将无法正常工作 我有以下基于ModernHttpClient的代码。有谁能建议在.Net标准2.0中如何处理这个问题,因为DLL添加不正确 internal class AuthenticatedHttpClientHandler : NativeMessageHandler { public AuthenticatedHt

我有一个老项目,它是在Xamarin.FormV2.5。不推荐使用的是PCL项目。我正在尝试升级,但for
ModernHttpClient
无法正常工作。这表明DLL将无法正常工作

我有以下基于
ModernHttpClient
的代码。有谁能建议在.Net标准2.0中如何处理这个问题,因为DLL添加不正确

internal class AuthenticatedHttpClientHandler : NativeMessageHandler
{
    public AuthenticatedHttpClientHandler()
    {
        CookieContainer = new CookieContainer();
    }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
        CancellationToken cancellationToken)
    {
        using (var cts = new CancellationTokenSource(System.TimeSpan.FromSeconds(30)))
        {
            var response = await base.SendAsync(request, cts.Token).ConfigureAwait(false);
            return response;
        }
    }
} 
内部类AuthenticatedHttpClientHandler:NativeMessageHandler
{
公共认证的HttpClientHandler()
{
CookieContainer=新CookieContainer();
}
受保护的覆盖异步任务SendAsync(HttpRequestMessage请求,
取消令牌(取消令牌)
{
使用(var cts=new CancellationTokenSource(System.TimeSpan.FromSeconds(30)))
{
var response=await base.sendaync(请求,cts.Token).ConfigureAwait(false);
返回响应;
}
}
} 
请建议

有谁能建议在.Net标准2.0中如何处理这个问题,因为DLL添加不正确

internal class AuthenticatedHttpClientHandler : NativeMessageHandler
{
    public AuthenticatedHttpClientHandler()
    {
        CookieContainer = new CookieContainer();
    }

    protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request,
        CancellationToken cancellationToken)
    {
        using (var cts = new CancellationTokenSource(System.TimeSpan.FromSeconds(30)))
        {
            var response = await base.SendAsync(request, cts.Token).ConfigureAwait(false);
            return response;
        }
    }
} 
如果您只需将
ModernHttpClient
安装到IOS/Android/UWP,就不会有问题。从本机平台中使用的
ModernHttpClient

解决方案:

删除仅为每个本机平台安装的Forms解决方案中安装的NuGet,则此警告将消失。如下所示:


右剪辑根解决方案项目->管理解决方案的NuGet包..->选择安装ModernHttpClient所需的本机平台,而不是选择表单项目选项

您可以使用@FabriBertani常规用户,谢谢。支持.Net标准2.0的
ModernHttpClient
是否有任何升级?或者我必须使用
HttpClient
Refit
?如果您仍然想使用ModernHttpClient,您可以尝试使用感谢。我有表单解决方案中的ModernHttpClient代码。如果我从表单解决方案中删除并将其添加到本机平台中,它将如何在表单解决方案中工作,因为类文件需要引用
ModernHttpClient
。请指导。您可以参考此代码。(如果以后有特定代码,将与您共享。如果答案有帮助,请记住标记。^^