Calling Twilio API from C#/.NET through a Proxy Server
<p>I am trying to run the C# <a href="https://www.twilio.com/docs/libraries/csharp" rel="nofollow noreferrer">sample twilio application</a> from behind a proxy web server. My proxy server needs authentication. Using the code below, I am able to authenticate successfully to the proxy server and make the Twilio call. However, Twilio returns me a <a href="https://www.twilio.com/docs/api/errors/20003" rel="nofollow noreferrer">code 20003</a> (Permission Denied). My AccountSID and AuthToken are correct. The below code (without the proxy settings) works just fine in a different environment that does not require a web proxy server.</p>

<p>My issue is <strong>similar to the issue and solution</strong> <a href="https://stackoverflow.com/questions/39378429/twilio-java-connection-with-proxy-authentication">posted here</a>, using Java, but I am unable to replicate the Java fix using C#/.NET. I am using .NET SDK 4.5 </p>

<pre><code>using System;
using Twilio;
using System.Net;

namespace TestTwilio
{
    class Program
    {
        static void Main(string[] args)
        {
            var accountSid = "xx";
            var authToken = "yy";

                var twilio = new TwilioRestClient(accountSid, authToken);twilio.Proxy = new System.Net.WebProxy("proxy.mycompany.com", 8080);
                    twilio.Proxy.Credentials = new NetworkCredential(“username”, “password”);

                var message = twilio.SendMessage("+1xxxxxxxxxx","+1xxxxxxxxxx", "Hello from C#");

            if (message.RestException != null)
            {
                var error = message.RestException.Message;
                Console.WriteLine(error);
                Console.WriteLine(message.RestException.MoreInfo);
                Console.WriteLine(message.Uri);
                Console.WriteLine(message.AccountSid);
                Console.Write("Press any key to continue.");
                Console.ReadKey();
            }
        }
    }
}
</code></pre>

<p>Thanks for helping out.</p>