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

SauravAnandSauravAnand USMember ✭✭

Hi,

I'm trying to make a POST request with WebRequest on Https endpoint but this gives me exception like: System.Net.WebException "SecureChannelFailure (The authentication or decryption has failed.)"

Xamarin Mac Project's target framework is : Mono/.Net 4.5

My Application was working fine 2 days ago and i didn't make any changes but now i'm getting this error.
Any help would be much appreciated.

Thanks,
Saurav

Tagged:

Answers

  • VarunBabuSVarunBabuS INMember ✭✭✭

    Hi @SauravAnand Could you once validate your POST request in tools like POSTMan or Fiddler to check if the issue is with Web Service\Web API or your code at client side

  • SauravAnandSauravAnand USMember ✭✭

    @VarunBabuS thanks for quick reply. POST request is alright as i'm using this same for my Windows based product but its giving this error in Mac version of same product & same code. Before 2 days it was fine. I'm not understanding what happened suddenly.

    Please show me some pointers. I have read/tried solutions available online but didn't work. I have tried like below before creating post request.

    System.Net.ServicePointManager.ServerCertificateValidationCallback +=
    delegate (object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate,
    System.Security.Cryptography.X509Certificates.X509Chain chain,
    System.Net.Security.SslPolicyErrors sslPolicyErrors)
    {
    return true;
    };
    ServicePointManager.ServerCertificateValidationCallback = MyRemoteCertificateValidationCallback;

    But with NO luck.

  • VarunBabuSVarunBabuS INMember ✭✭✭

    Hi @SauravAnand If your requirement is to do a POST request could please try below code

    Data that needs to be posted using below line

    var PostData = JsonConvert.SerializeObject(jsonResult)

    Posting the above data using below code

    using (HttpClient httpClient = new HttpClient())
    {
    httpClient.DefaultRequestHeaders.Accept.Clear();
    httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", Token);
    httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    HttpResponseMessage response = await httpClient.PostAsync(baseAddress, new StringContent(PostData, Encoding.UTF8, "application/json"));

                            response.EnsureSuccessStatusCode();
                            string content = await response.Content.ReadAsStringAsync();
    
                            return content;
                        }
    

    meanwhile i will try to validate your code

  • SauravAnandSauravAnand USMember ✭✭

    @VarunBabuS I'm still facing the same issue. Can you please help me.

Sign In or Register to comment.