Hello
I'm using url with HTTPS in Xamarin PCL and here is my codes;
public static async Task<Result<K>> post<K>(string method, T item, bool willReplaceResponse) { HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Add(Resources.AppResources.API_KEY_HEADER_KEY, Resources.AppResources.API_KEY); //POST_URL = "https://........ string URL = Resources.AppResources.POST_URL + method; try { var json = JsonConvert.SerializeObject(item); var content = new StringContent(json, Encoding.UTF8, "application/x-www-form-urlencoded"); HttpResponseMessage response = await client.PostAsync(URL, content); if (response.IsSuccessStatusCode) { //do something } } }
In this code; PostAsync method is not working and crashed.
Actually in Iphone Simulator is working good. But in Android Emulator I've got never response.IsSuccessStatusCode = true. I have been got crash that is System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) ---> System.IO.IOException: The authentication or decryption has failed. ---> System.IO.IOException: The authentication or decryption has failed. ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed.
Faced this issue yestarday...
Add ModernHttpClient plugin to all your projects (PCL, Android, iOS, WP (etc.)).
After that, put new NativeMessageHandler() as a parameter of new HttpClient().
// *NativeMessageHandler*, from *ModernHttpClient* plugin has been introduced, // because lack of HTTPS requests handling, with OOTB implementation. // Previously, there has been thrown exception, while HTTPS requests: // System.Net.WebException: Error: SecureChannelFailure (The authentication or decryption has failed.) // ---> System.IO.IOException: The authentication or decryption has failed. // ---> System.IO.IOException: The authentication or decryption has failed. // ---> Mono.Security.Protocol.Tls.TlsException: The authentication or decryption has failed _httpClient = new HttpClient(new NativeMessageHandler());
Answers
Faced this issue yestarday...
Add ModernHttpClient plugin to all your projects (PCL, Android, iOS, WP (etc.)).
After that, put new NativeMessageHandler() as a parameter of new HttpClient().
Apologise for late returning. Thank you very much, it is working well now. @NamyslawSzymaniuk
Good to hear that
!
did not work for me. same issue as before... running out of ideas.
Worked for me. Thanks.
it seems ModernHttpClient only works for .Net 4.6.1 or up, it does not work for .net standard 2.0+