Xamarin C# Error: SecureChannelFailure (The authentication or decryption has failed.)

只谈情不闲聊 提交于 2019-12-21 05:22:11

问题


I use this:

        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;`

and i get the error in the headline.

What i do not understand is that if i use the same code in a console application in Visual Studio, i get the expected result! But if i use this code in my android app i get the error in the headline. i tried it on the emulator and with a device.


回答1:


Using ModernHttpClient didn't work for me. What did work was changing some settings in the Android project. Start by right clicking on the project and selecting Properties.

Android Options > Advanced > HttpClient implementation = Android

Android Options > Advanced > SSL/TLS implementation = Native TLS 1.2+

I'm on Visual Studio 2017.




回答2:


Use ModernHttpClient Nuget Package and create HttpClient instance like- HttpClient client = new HttpClient(new NativeMessageHandler());

otherwise go to android build option and change settings = right click android project => properties =>Select Android Option tab => click on Advanced => and change HttpClient Implementation => default to Android and change SSL/TLS implementation => Default to Native TLS 1.2+

These both options worked for me.



来源:https://stackoverflow.com/questions/42706055/xamarin-c-sharp-error-securechannelfailure-the-authentication-or-decryption-ha

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!