开发者

How do I display the system's default http proxy

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 tar开发者_JAVA技巧getserver = 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?


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

string proxyServerAddress = proxyserver.AbsoluteUri;


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.


Wouldn't this just be something like:

Textbox1.Text = proxyserver.ToString();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜