Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

Using PAC files proxy

, 4 Nov 2005
This article explains how to set a proxy using PAC files.
pacproxyusage.zip
PacProxyUsage.exe
pacproxyusage_src.zip
Proxy.pac
PacProxyUsage.csproj.user
App.ico
using System;
using System.Net;
using System.IO;
namespace PacProxyUsage
{
	/// <summary>
	/// Summary description for ProxyTest.
	/// </summary>
	class ProxyTest
	{
		/// <summary>
		/// The main entry point for the application.
		/// </summary>
		[STAThread]
		static void Main(string[] args)
		{
            Stream RequestStream  = null;
            string DestinationUrl = "http://www.google.com";
            string PacUri         = "http://127.0.0.1/proxy.pac1";
            
            
            // Create test request 
			WebRequest TestRequest = WebRequest.Create ( DestinationUrl );
            
            // Optain Proxy address for the URL 
            string ProxyAddresForUrl = Proxy.GetProxyForUrlUsingPac ( DestinationUrl, PacUri );
            if ( ProxyAddresForUrl != null ){
                Console.WriteLine ("Found Proxy: {0}", ProxyAddresForUrl );
                TestRequest.Proxy = new WebProxy ( ProxyAddresForUrl ) ;
            }else{                
                Console.WriteLine ( "Proxy Not Found. Send request directly."  );
            }
            
            try {
                WebResponse TestResponse = TestRequest.GetResponse();
                Console.WriteLine ( "Request was successful" );
            }catch ( Exception ex ){
                Console.WriteLine ( "Error: {0}", ex.Message );
            }finally{
                if ( RequestStream != null ){
                    RequestStream.Close();
                }
            }
            Console.ReadLine();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Glaxalg
Software Developer (Senior)
United States United States
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.141223.1 | Last Updated 4 Nov 2005
Article Copyright 2005 by Glaxalg
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid