locked
Https web service doesn't work on PostAsync method RRS feed

  • Question

  • User233609 posted

    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.

    Friday, August 19, 2016 12:40 PM

Answers

  • User240159 posted

    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());
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 19, 2016 1:36 PM

All replies

  • User240159 posted

    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());
    
    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Friday, August 19, 2016 1:36 PM
  • User233609 posted

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

    Monday, August 22, 2016 11:26 AM
  • User240159 posted

    Good to hear that :wink: !

    Monday, August 22, 2016 11:27 AM
  • User207056 posted

    @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.

    Monday, October 24, 2016 10:04 AM
  • User148199 posted

    @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.

    Friday, December 16, 2016 8:52 AM
  • User190256 posted

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

    Saturday, June 22, 2019 11:49 PM