如何使用代理设置,用户名和密码在Windows应用程序中配置app.config文件 [英] How to configure a app.config file in windows application with proxy settings, username and password
本文介绍了如何使用代理设置,用户名和密码在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
这篇关于如何使用代理设置,用户名和密码在Windows应用程序中配置app.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文