问题
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