Forum Xamarin.Android
We are excited to announce that the Xamarin Forums are moving to the new Microsoft Q&A experience. Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

We encourage you to head over to Microsoft Q&A for .NET for posting new questions and get involved today.

web request error on https

Hi, i have a problem with getting response from https rest service. In researchs i found that problem caused MONO.

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

Can anyone help me ?

Answers

  • MabroukMabrouk USMember ✭✭✭

    hi, @umutaydin

    Can you show us a part of code?

  • umutaydinumutaydin TRMember
       Hi @Mabrouk ,
    

    I try a lot of version. The last version like that;

    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; // **** Always 
    };//(o, certificate, chain, errors) => true;
    
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    
    var request = HttpWebRequest.Create(url);
    request.ContentType = "application/json";
    request.Method = "GET";
    request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(uname + ":" + pass));
    
     using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
     {
        if (response.StatusCode != HttpStatusCode.OK)
                Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                return reader.ReadToEnd();
            }
    }
    
  • umutaydinumutaydin TRMember

    Hi @Mabrouk ,

    I try a lot of version. The last version like that;

    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; // **** Always 
    };//(o, certificate, chain, errors) => true;
    
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3;
    
    var request = HttpWebRequest.Create(url);
    request.ContentType = "application/json";
    request.Method = "GET";
    request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.Default.GetBytes(uname + ":" + pass));
    
     using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
     {
        if (response.StatusCode != HttpStatusCode.OK)
                Console.Out.WriteLine("Error fetching data. Server returned status code: {0}", response.StatusCode);
            using (StreamReader reader = new StreamReader(response.GetResponseStream()))
            {
                return reader.ReadToEnd();
            }
    }
    
  • JTEJTE USMember ✭✭

    I have the same issue. search web and found out that ModernHttpClient might help, well it did not at least i my case.

  • RobynDessoyRobynDessoy USMember

    @JuhaTervo I've had the same issue and ModernHttpClient did not work for me either. I'm really stuck as to whats going on here!

    There's a bug open currently against Mono which I think might be involved https://bugzilla.xamarin.com/show_bug.cgi?id=26658

  • JTEJTE USMember ✭✭

    I got it working in UWP application but not in android. I sort of made workaround By making callback to the backend that directs (orginal) data to azure table storage and I read the data from azure data storage. not pretty but it works.

Sign In or Register to comment.