如何使用代理设置,用户名和密码在Windows应用程序中配置app.config文件

问题描述:

我只想从我的Windows应用程序访问www.google.com。

我的意思是我的网络请求应该通过代理并访问网页。

但是我的代理服务器阻止了我。所以我需要在app.config文件中或使用c#后面的代码中配置代理用户名,密码和设置。

我用Google搜索并进行了很多尝试。

所以帮助我做这件事。在此先感谢

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

您好,



在配置文件中保存密码不是一个好主意。



在你的情况下,我认为默认代理可以解决问题。



如何获取系统Web代理: http://msdn.microsoft.com/en-us/library/system .net.webrequest.getsystemwebproxy.aspx [ ^ ]



示例:

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");
    }





谢谢

Suvabrata



Thanks
Suvabrata