Forum Cross Platform with Xamarin

How to include cert in httpclient

slycoderslycoder USMember
edited December 2016 in Cross Platform with Xamarin

I'm trying to load and use a cert for an https call like this:

        using System.Net.Http;

        var handler = new WebRequestHandler { ClientCertificateOptions = ClientCertificateOption.Manual, }; //error here
        handler.ClientCertificates.Add(new X509Certificate2(File.ReadAllBytes("Resources/cert.pfx"), "ghjghjgh"));
        handler.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;

        using (HttpClient client = new HttpClient(handler, false))
            var text = await client.GetStringAsync("https api address");

I'm getting a runtime error on new WebRequestHandler():

Unhandled Exception: System.InvalidProgramException: Invalid IL code in System.Net.Http.WebRequestHandler:.ctor (): method body is empty.

How can I fix this or load a .cfx or .cer from my android app filesystem to use in an httpclient? I had to include the System.Net.Http.WebRequest dll to my project.

Sign In or Register to comment.