Using Your FoxyProxy Account with C# and .NET

  1. Home
  2. Using Your FoxyProxy Account with C# and .NET

Here’s a code snippet that uses your FoxyProxy account with C# and .NET.

This example connects to https://icanhazip.com through a proxy server with your proxy username and password. Be sure to replace username, password, hostname.getfoxyproxy.org and port (typically 3128 or 13129) in this example with your account information.

This C# client connects to the proxy server using HTTP and instructs the proxy server to connect to the final destination (icanhazip.com) using HTTPS. It is compatible with current .NET versions and back to 1.1.

Although this example uses the HTTP proxy server on port 13129, other ports are available with your account. HTTPS proxy server access is also available on the same ports, which encrypts traffic between your client and FoxyProxy proxy servers. Your account also comes with SOCKS5 proxy server access, typically on port 21. You can find this information by logging into your account at the Control Panel.


using System;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.IO;

namespace Proxy_Test
{
    class Credentials : ICredentials
    {

        public NetworkCredential GetCredential(Uri uri, string authType)
        {
            return new NetworkCredential("your_username", "your_password");
        }
    }

    class program
    {
        static void Main()
        {
            Task t = new Task(HTTP_GET);
            t.Start();
            Console.ReadLine();
        }

        static async void HTTP_GET()
        {
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://icanhazip.com/");
            WebProxy myproxy = new WebProxy("foxyproxy_server:foxyproxy_port", true, null, new Credentials());
            request.Proxy = myproxy;
            request.Method = "GET";
            using (var response = (HttpWebResponse)request.GetResponse())
            {
                var encoding = Encoding.GetEncoding(response.CharacterSet);

                using (var responseStream = response.GetResponseStream())
                using (var reader = new StreamReader(responseStream, encoding))
                    // Output the response
                    Console.WriteLine(reader.ReadToEnd());
            }
        }
    }
}