using System;
using System.IO;
using System.Net;

namespace ProxyRequest
{
    class MainClass
    {
        public static void Main (string[] args)
        {
            string apiKey = "<Insert_here_your_APIkey>:"; //Left the ":" sign at the end.
            
            var myProxy = new WebProxy("http://proxy.crawlera.com:8010");
            
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://httpbin.org/ip");
            
            var encodedApiKey = Base64Encode(apiKey);
            
            request.Headers.Add("Proxy-Authorization", "Basic "+ encodedApiKey);
            
            request.Proxy = myProxy;
            
            request.PreAuthenticate = true;
            request.ServerCertificateValidationCallback += (sender, certificate, chain, sslPolicyErrors) => true;
            
            WebResponse response = request.GetResponse();
            
            Console.WriteLine("Response Status: " + ((HttpWebResponse)response).StatusDescription);
            
            Console.WriteLine("\nResponse Headers:\n" + ((HttpWebResponse)response).Headers);
            
            Stream dataStream = response.GetResponseStream();
            
            var reader = new StreamReader(dataStream);
            
            string responseFromServer = reader.ReadToEnd();
            
            Console.WriteLine("Response Body:\n" + responseFromServer);
            
            reader.Close();
            response.Close();
            
        }
        
        public static string Base64Encode(string apiKey) 
            
            {
            var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(apiKey); 
            return System.Convert.ToBase64String(plainTextBytes);
            }
    }
}   



Warning


Some HTTP client libraries including Apache HttpComponents Client and .NET don't send authentication headers by default. This can result in doubled requests so pre-emptive authentication should be enabled where this is the case.


In the above example we are making HTTPS requests to https://twitter.com through Crawlera. It is assumed that Crawlera Certificate has been installed, since CONNECT method will be employed.