Https web service doesn't work on PostAsync method

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.

Tagged:

Best Answer

Answers

  • aybkekaraarslanaybkekaraarslan USMember ✭✭

    Apologise for late returning. Thank you very much, it is working well now. @NamyslawSzymaniuk

  • NamyslawSzymaniukNamyslawSzymaniuk USMember ✭✭✭✭

    Good to hear that :wink: !

  • JTEJTE USMember ✭✭

    @NamyslawSzymaniuk said:
    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());
    

    did not work for me. same issue as before... running out of ideas.

  • SuatKorkmazSuatKorkmaz USMember ✭✭✭
    edited December 2016

    @NamyslawSzymaniuk said:
    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());
    

    Worked for me. Thanks.

  • ShawnZhengShawnZheng USMember ✭✭

    it seems ModernHttpClient only works for .Net 4.6.1 or up, it does not work for .net standard 2.0+

Sign In or Register to comment.