I try to create an app in "Microsoft Visual Studio 2017" Xamarin Android App.
If i repelasd with http and not (https) it works fine
My qustion is: How can i reguest a https call?
Basic code:
using Android.App;
using Android.Widget;
using Android.OS;
using Android.Support.V7.App;
using System.Net.Http;
using System;
using System.Text;
using System.Net;
using System.IO;
//System.Net.WebException: Error: TrustFailure (The authentication or decryption has failed.)
namespace httprequest
{
[Activity(Label = "@string/app_name", Theme = "@style/AppTheme", MainLauncher = true)]
public class MainActivity : AppCompatActivity
{
private static readonly HttpClient client = new HttpClient();
Button btn1;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
// Set our view from the "main" layout resource
SetContentView(Resource.Layout.activity_main);
if (Build.Brand.Equals("GENERIC", StringComparison.InvariantCultureIgnoreCase))
{
ServicePointManager.ServerCertificateValidationCallback +=
(sender, cert, chain, sslPolicyErrors) => true;
}
btn1 = FindViewById<Button>(Resource.Id.httpbtn1);
btn1.Click += delegate
{
using (var wb = new WebClient())
{
var request = (HttpWebRequest)WebRequest.Create("https://???");
request.KeepAlive = false;
request.ProtocolVersion = HttpVersion.Version10;
var response = (HttpWebResponse)request.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
}
};
}
}
}
Here is what i get:
Unhandled Exception: System.Net.WebException: Error: TrustFailure (One or more errors occurred.)
In Advanced Adnroid Properites:
HttpClient implementation: Android
SSL/TLS implementation: Native TLS 1.2+