Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin C错误:SecureChannelFailure(身份验证或解密失败。)_Xamarin_Webclient - Fatal编程技术网

Xamarin C错误:SecureChannelFailure(身份验证或解密失败。)

Xamarin C错误:SecureChannelFailure(身份验证或解密失败。),xamarin,webclient,Xamarin,Webclient,我用这个: WebClient mClient = new WebClient(); mClient.UseDefaultCredentials = false; mClient.Credentials = new NetworkCredential("Name", "Password"); Uri mUrl = new System.Uri("https://server"); mClient.DownloadDa

我用这个:

        WebClient mClient = new WebClient();
        mClient.UseDefaultCredentials = false;
        mClient.Credentials = new NetworkCredential("Name", "Password");
        Uri mUrl = new System.Uri("https://server");
        mClient.DownloadDataAsync(mUrl);
        mClient.DownloadDataCompleted += MClient_DownloadDataCompleted;`
我在标题上看到了错误


我不明白的是,如果我在VisualStudio的控制台应用程序中使用相同的代码,我会得到预期的结果!但如果我在android应用程序中使用此代码,我会在标题中看到错误。我在模拟器和设备上试用了它。

使用ModernHttpClient对我不起作用。我们所做的工作是改变Android项目中的一些设置。首先,在项目上单击鼠标右键并选择“属性”

Android选项>高级>HttpClient实现=Android

Android选项>高级>SSL/TLS实现=本机TLS 1.2+


我使用的是Visual Studio 2017。

使用ModernHttpClient Nuget包并创建HttpClient实例,如- HttpClient客户端=新建HttpClientnew NativeMessageHandler

否则,转到android构建选项并更改设置= 右键单击android项目=>属性=>选择android选项选项卡=>单击高级=>并将HttpClient实现=>默认值更改为android 并将SSL/TLS实现=>默认值更改为本机TLS 1.2+


这两个选项对我都有效。

解决方案是:使用NuGet提供的modernhttpclient包,HttpClient=new HttpClientnew NativeMessageHandler;我知道这是Android的设置。但同样的问题也发生在ios上。但我找不到ios解决方案属性的SSL/TLS实现选项。即使使用此选项,问题也会在极少数情况下突然出现