Handling WebProxy


The WebProxy class contains the proxy settings that WebRequest instances use to determine whether a Web proxy is used to send requests. The WebProxy class is the base implementation of the IWebProxy interface.

The WebProxy class supports automatic detection and execution of proxy configuration scripts. This feature is also known as Web Proxy Auto-Discovery (WPAD).
The following code will explain the webproxy


String MyRequestUrl = "http://www.dotnetspider.com/";

HttpWebRequest MyHttpWebRequest = null;
StreamReader MyStringReader = null;
HttpWebResponse MyHttpWebResponse = null;

try{

MyHttpWebRequest = (MyHttpWebRequest) WebRequest.Create(MyRequestUrl);
MyHttpWebRequest.Method = "GET";

MyHttpWebRequest.Proxy = new WebProxy("http://myproxy:80/");
// fails unless a real proxy is specified

MyHttpWebResponse = (MyHttpWebResponse) MyHttpWebRequest.GetResponse();
MyStringReader = new StreamReader(MyHttpWebResponse.GetResponseStream());

String Results = MyStringReader.ReadToEnd();
MyWebResponseLabel.Text = Results;

}

finally
{
try
{
MyStringReader.Close();
MyHttpWebResponse.Close();
MyHttpWebRequest.Abort();
}
catch
{

}
}


By
Nathan


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: