Click here to Skip to main content
15,881,089 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I just wanted to access www.google.com from my windows application.
I mean that my web request should cross the proxy and access the webpage.
But my proxy server is blocking me. So i need to configure the proxy username, password and settings in app.config file or in code behind using c#.
I have googled it and made lot of tries.
So help me in doing it. Thanks in advance
Posted

1 solution

Hi,

Its not a good idea to save password in config file.

In your case I think default proxy will do the trick.

How to Get System web proxy : http://msdn.microsoft.com/en-us/library/system.net.webrequest.getsystemwebproxy.aspx[^]

Example :
HttpWebRequest myWebRequest=(HttpWebRequest)WebRequest.Create("http://www.google.com");

    // Obtain the 'Proxy' of the  Default browser.  
    IWebProxy proxy = myWebRequest.Proxy;
    // Print the Proxy Url to the console.
    if (proxy != null)
    {
        Console.WriteLine("Proxy: {0}", proxy.GetProxy(myWebRequest.RequestUri));
    } 
    else
    {
        Console.WriteLine("Proxy is null; no proxy will be used");
    }


Thanks
Suvabrata
 
Share this answer
 
Comments
Bernhard Hiller 11-Jun-14 2:29am    
That's a very strange way ... as described in MSDN. I fail to believe it. I'd rather think of
myWebRequest.Proxy = myWebRequest.GetSystemWebProxy();
Fortunately I do not need to cope with web proxies.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900