Hello All,
I am using HttpWebRequest to fetch webpages in my ASP.net C#
application. The request works fine without the proxy, but on using the code
from within a network that uses proxy the request does not work. I tried to
use the MS code to get around it, but having problems using it. The first
thing is that the this conversion
myProxy=(WebPro xy)myWebRequest .Proxy;
does not work, and I get an error of cannot convert Webproxywrapper to
WebProxy.
The MS code is as under.
http://msdn.microsoft.com/library/de...ProxyTopic.asp
// Create a new request to the mentioned URL.
HttpWebRequest
myWebRequest=(H ttpWebRequest)W ebRequest.Creat e("http://www.microsoft.c om");
WebProxy myProxy=new WebProxy();
// Obtain the 'Proxy' of the Default browser.
myProxy=(WebPro xy)myWebRequest .Proxy;
// Print the Proxy Url to the console.
Console.WriteLi ne("\nThe actual default Proxy settings are
{0}",myProxy.Ad dress);
try
{
Console.WriteLi ne("\nPlease enter the new Proxy Address that is to be
set:");
Console.WriteLi ne("(Example:ht tp://myproxy.com:por t)");
string proxyAddress;
proxyAddress =Console.ReadLi ne();
if(proxyAddress .Length>0)
{
Console.WriteLi ne("\nPlease enter the Credentials ");
Console.WriteLi ne("Username:") ;
string username;
username =Console.ReadLi ne();
Console.WriteLi ne("\nPassword: ");
string password;
password =Console.ReadLi ne();
// Create a new Uri object.
Uri newUri=new Uri(proxyAddres s);
// Associate the newUri object to 'myProxy' object so that new
myProxy settings can be set.
myProxy.Address =newUri;
// Create a NetworkCredenti al object and associate it with the Proxy
property of request object.
myProxy.Credent ials=new NetworkCredenti al(username,pas sword);
myWebRequest.Pr oxy=myProxy;
}
Console.WriteLi ne("\nThe Address of the new Proxy settings are
{0}",myProxy.Ad dress);
HttpWebResponse
myWebResponse=( HttpWebResponse )myWebRequest.G etResponse();
Can anyone please help me with this?
thanks a lot.
Imran.