Demo 2: C#

An example of how to call the facial comparison compare endpoint using C#

    using System;
    using System.IO;
    using System.Net.Http;
    using System.Threading.Tasks;
    using Newtonsoft.Json;

    public class ComparisonResult
    {
        public bool IsMatch { get; set; }

        public int Confidence { get; set; }
    }

    public class Program
    {
        static async Task Main(string[] args)
        {
            var client = new HttpClient();

            var content = new MultipartFormDataContent();

            content.Add(new ByteArrayContent(File.ReadAllBytes("/face1.png")), "Current", "current.png");

            content.Add(new ByteArrayContent(File.ReadAllBytes("/face2.png")), "Comparison", "comparison.png");

            content.Add(new StringContent("123"), "ClientReference");

            var response = await client.SendAsync(new HttpRequestMessage
            {
                Method = HttpMethod.Post,
                Headers = { { "Authorization", "Basic YourApiKey" } },
                RequestUri = new Uri("https://api.w2globaldata.com/facial-comparison/compare?api-version=1.1"),
                Content = content
            });

            var comparisonResult = JsonConvert.DeserializeObject<ComparisonResult>(
                await response.Content.ReadAsStringAsync());

            Console.WriteLine($"Comparison result: {comparisonResult.IsMatch}");

            Console.ReadLine();
        }
    }