c# webproxy - 一次大冒险?
从昨天开始,我开始接触 .Net WebProxy 类,因为我认为 Web 代理的使用是开发具有 Web 访问的应用程序的一大陷阱(我的 Java 经验)。
所以我做了一个测试用例:
我使用了一个没有代理身份验证的鱿鱼代理,并在我的“ms Internet Explorer”中定义了代理设置,因为一个朋友告诉我,.net框架从Internet Explorer(一个大的.net)获取代理设置我认为的框架功能)。我的 C# 测试应用程序尝试下载 google,是的,它有效。
测试用例来源:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
WebResponse Response = request.GetResponse();
Stream WebStream = Response.GetResponseStream();
StreamReader Reader = new StreamReader(WebStream);
string PageContent = Reader.ReadToEnd();
Console.WriteLine(PageContent);
Reader.Close();
WebStream.Close();
Response.Close();
好的,我尝试了下一步 - 我使用带有身份验证的鱿鱼代理。我只输入了 Internet Explorer 的代理 IP 和端口,而不输入凭据。然后我再次开始我的应用程序,霍莉狗屎 - 它也有效......但它怎么可能 - 我想。 .net框架的解决方案使用了旧的代理设置——无需身份验证的代理。
所以我的第一个问题是怎么会这样? .net 框架如何知道它可以使用哪个代理? 下一个任务是 - 我可以为我的应用程序使用“ms internet explorer”代理设置(带身份验证)吗?
感谢您的回答, Kangee
P.S.:我来自德国 - 我希望我的英语足以理解我的问题:-)
since yersterday i play a little bit with the .Net WebProxy Class, because i think the usage of webproxys in one of the big traps in the development of applications with web access (my java experience).
So i made a test case:
i used a squid proxy without proxy authentication and defined the proxy settings in my "ms internet explorer" because a friend told my that the .net framework take the proxy setting from the internet explorer (a big .net framework feature i thought). my c# test application tried to download google and yes it works.
Testcase-Source:
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://www.google.com");
WebResponse Response = request.GetResponse();
Stream WebStream = Response.GetResponseStream();
StreamReader Reader = new StreamReader(WebStream);
string PageContent = Reader.ReadToEnd();
Console.WriteLine(PageContent);
Reader.Close();
WebStream.Close();
Response.Close();
Ok i tried the next step - i used a squid proxy with authentication. I entered only the proxy-ip and port to the internet explorer and not the credentials. Then i start my application again and holly sh*t - it works too... but how can it be - i thought. The solution the .net framework used the old proxys settings - the proxy without authentication.
So my first question is how can it be? How does the .net frameworks knows which proxy it can use?
And the next quest is - can i used the "ms internet explorer"-proxy settings (with authentication) for my application?
Thanks for your answers,
Kangee
P.S.: I am from germany - i hope my english is good enough to understand my question :-)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论