15.9 Requesting Web Documents Through a Proxy Server

 <  Day Day Up  >  

You want to read a Web document but must go through a proxy server to do so.


Technique

You manage proxies by creating a WebProxy object and setting it as the default proxy that is used by all Web requests within your application. When creating a WebProxy object, pass the proxy server address and port number to the constructor. You can then set the default proxy server for all Web requests by calling the static method Select defined in the GlobalProxySelection class:

 
 void SetProxy( string address, int port ) {     WebProxy proxyObject = new WebProxy( address, port );     // don't use proxy for local addresses     proxyObject.BypassProxyOnLocal = true;     // make change global     GlobalProxySelection.Select = proxyObject; } 

Comments

Most businesses use firewalls as a way to prevent external machines from accessing an internal network. An external computer attempting to access a machine in the internal network is denied access by the firewall. This arrangement, of course, presents a dilemma for two-way communication protocols such as HTTP. Because HTTP is a connection-oriented protocol, it requires a client to send data to the server and vice versa. If a firewall exists at the client site, the server cannot service the client request. To solve this problem, you can use a proxy server. This server acts as a liaison between the server and client, whereby all communication between the two first goes through the proxy server.

Using a proxy server within the .NET Framework is a trivial matter. In fact, in most cases, you might not need to ask the user to specify the proxy address to use. The GlobalProxySelection by default uses the proxy returned by the WebProxy.GetDefaultProxy , which itself appears within the Internet Explorer settings.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net