// Create a new request to the mentioned URL. HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com"); WebProxy myProxy=new WebProxy(); string proxyAddress;try { proxyAddress =Console.ReadLine(); if(proxyAddress.Length>0) { Console.WriteLine("\nPlease enter the Credentials (may not be needed)"); Console.WriteLine("Username:"); string username; username =Console.ReadLine(); Console.WriteLine("\nPassword:"); string password; password =Console.ReadLine(); // Create a new Uri object. Uri newUri=new Uri(proxyAddress); // Associate the newUri object to 'myProxy' object so that new myProxy settings can be set. myProxy.Address=newUri; // Create a NetworkCredential object and associate it with the // Proxy property of request object. myProxy.Credentials=new NetworkCredential(username,password); myWebRequest.Proxy=myProxy; } HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse(); } ...
HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.microsoft.com");
WebProxy myProxy=new WebProxy();
string proxyAddress;try
{
proxyAddress =Console.ReadLine();
if(proxyAddress.Length>0)
{
Console.WriteLine("\nPlease enter the Credentials (may not be needed)");
Console.WriteLine("Username:");
string username;
username =Console.ReadLine();
Console.WriteLine("\nPassword:");
string password;
password =Console.ReadLine();
// Create a new Uri object.
Uri newUri=new Uri(proxyAddress);
// Associate the newUri object to 'myProxy' object so that new myProxy settings can be set.
myProxy.Address=newUri;
// Create a NetworkCredential object and associate it with the
// Proxy property of request object.
myProxy.Credentials=new NetworkCredential(username,password);
myWebRequest.Proxy=myProxy;
}
HttpWebResponse myWebResponse=(HttpWebResponse)myWebRequest.GetResponse();
}
...