81363

HTTPS Post failure

Question:

I´m trying to send a POST request to an API on my Xamarin Forms application and I´m getting an error that indicates that there is no trust relationship when sending the request. I cannot find out why is this and how to solve it. This is the exception:

<blockquote>

System.Net.Http.HttpRequestException: An error occurred while sending the request ---> System.Net.WebException: Error: TrustFailure (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: Invalid certificate received from server. Error code: 0xffffffff800b010f at Mono.Security.Protocol.Tls.RecordProtocol.EndReceiveRecord (System.IAsyncResult asyncResult) [0x00031] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/RecordProtocol.cs:430 at Mono.Security.Protocol.Tls.SslClientStream.SafeEndReceiveRecord (System.IAsyncResult ar, System.Boolean ignoreEmpty) [0x00000] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs:256 at Mono.Security.Protocol.Tls.SslClientStream.NegotiateAsyncWorker (System.IAsyncResult result) [0x00071] in /Users/builder/jenkins/workspace/xamarin-android/xamarin-android/external/mono/mcs/class/Mono.Security/Mono.Security.Protocol.Tls/SslClientStream.cs:418 --- End of inner exception stack trace ---

</blockquote>

The code resulting in this exception is the following:

MultipartFormDataContent content = new MultipartFormDataContent(); content.Headers.Add("X-Auth-Token", "eb27c17f-8bd6-4b94-bc4f-742e361b4e6a"); content.Headers.ContentType = MediaTypeHeaderValue.Parse("image/jpeg"); content.Add(new ByteArrayContent(myByteImage)); try { HttpResponseMessage response = await _client.PostAsync("https://10.54.66.160:9000/3/matching/search?list_id=3c9f2623-28be-435f-a49f-4dc29c186809&limit=1", content); string responseContent = await response.Content.ReadAsStringAsync(); } catch (Exception ex) { throw; }

Answer1:

It seems the problem solved putting the following code on MainActivity.cs

System.Net.ServicePointManager.ServerCertificateValidationCallback += (sender, cert, chain, sslPolicyErrors) => { if (cert != null) System.Diagnostics.Debug.WriteLine(cert); return true; };

As @DanielA.White It seems that the mono implementation of HttpClient does not support self signed certificates.

Recommend

  • spring hibernate Async task issue No Session found for current thread
  • Azure dev fabric crashes with SocketException when using DotNetOpenAuth
  • Office Dialog API send message to child dialog
  • How can I load several 3D geometries in a separate thread without running into thread ownership issu
  • WCF - AsyncPattern Performance
  • WebClient “error getting response stream”
  • Problem with sockets and OutOfMemory error
  • Hudson: What is a good way to store a variable between the two job runs?
  • Relinquish the thread/CPU until async call completes in Akka and Java?
  • Jenkins and updating git submodules
  • web.xml configuration based on Maven profile
  • call monodroid method from javascript example
  • com.jcraft.jsch.JSchException: Algorithm negotiation fail
  • Gradle failed to build with error Multiple dex files define
  • Deploying Tizen app to Gear S2: Non trusted certificate is used
  • “'1.0.0' is not a valid short file name” when installing Xamarin IOS.Setup and Android.Set
  • Upgrade from Jenkins Weekly to LTS
  • SwipeListView in Xamarin Form
  • Gradle test fails with NullPointerException
  • Intellisense keeps showing errors while build is successful Visual Studio 2015
  • Trying to get all column names in a table
  • How to import Navit into Eclipse and use it in own android project
  • How to set the navigation bar to the top in Table View?
  • UIPickerView without IB?
  • Mapping two workspace folders to the same working directory
  • How to make HttpWebRequest async
  • Cassandra NoClassDefFoundError: com/google/common/util/concurrent/AsyncFunction
  • SqlCommand back up Database
  • Pass Dictionary to Javascript array
  • Button text different than value submitted in query string
  • Odoo 10 - Overriding unlink method
  • C++ Partial template specialization - design simplification
  • SignalR .NET Client Invoke throws an exception
  • How to make a tree having multiple type of nodes and each node can have multiple child nodes in java
  • Updating server-side rendering client-side
  • Cassandra Data Model
  • QuartzCore.framework for Mono Develop
  • Codeigniter doesn't let me update entry, because some fields must be unique
  • Proper way to use connect-multiparty with express.js?
  • How to get NHibernate ISession to cache entity not retrieved by primary key