如何确定(优雅地)在 C# winforms 应用程序中是否需要代理身份验证 [英] How do I determine (elegantly) if proxy authentication is required in C# winforms app
问题描述
我的用例是这样的,我想调用一个网络服务,如果我在需要身份验证的代理服务器后面,我只想使用默认凭据...
My use case is this, I want to call out to a webservice and if I am behind a proxy server that requires authentication I want to just use the default credentials...
WebRequest.DefaultWebProxy.Credentials = CredentialCache.DefaultCredentials;
否则我只会简单地进行调用,最好预先确定是否需要身份验证,而不是在我尝试进行调用后处理异常.
Otherwise I'll just simply make the call, It would be very nice to determine if the auth is required up front, rather than handle the exception after I attempt to make the call.
想法?
推荐答案
System.Net.WebProxy
有一个名为 UseDefaultCredentials
的属性,可能成为你想要的(但我不得不承认这里有点无知).相关文档的链接位于此处.
System.Net.WebProxy
has a property called UseDefaultCredentials
that may be what you want (but I have to admit a bit of ignorance here). The link to the relevant documentation is here.
这篇关于如何确定(优雅地)在 C# winforms 应用程序中是否需要代理身份验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!