tags:

views:

41

answers:

3

Hi I want to get the default system web proxy and display the resulting proxy address and port for http in a text box.

        IWebProxy oProxy = System.Net.WebRequest.GetSystemWebProxy();

        //to get default proxy settings 
        oProxy.Credentials = CredentialCache.DefaultNetworkCredentials;
        Uri targetserver = new Uri("http://www.google.com/");
        Uri proxyserver = oProxy.GetProxy(targetserver);

the above code in debug allows me to hover over proxysever and show all i need but i can't access the properties!

what am I missing?

A: 

This code looks fine. If you need the proxy server:

string proxyServerAddress = proxyserver.AbsoluteUri;
Robaticus
Thank you I was assigning it directly to a text box but for some reason that did not work!? but assigning it to a string first works :)
Adrian
A: 

According to the MSDN documentation, GetProxy returns the proxy that was explicitly set on an HttpRequest, not the system-default proxy.

Use WebRequest.DefaultWebProxy to get the IE proxy setting.

Dave Swersky
I just tried his code, and it works to get the default proxy, as well.
Robaticus
Could you show me the code as I could not get this to work!thanks
Adrian
A: 

Wouldn't this just be something like:

Textbox1.Text = proxyserver.ToString();
Jerome
this just returns the type and not the value :(
Adrian