如何确定(优雅),如果在C#WinForms应用程序需要代理认证 [英] How do I determine (elegantly) if proxy authentication is required in C# winforms app

查看:144
本文介绍了如何确定(优雅),如果在C#WinForms应用程序需要代理认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的用例是这样的,我想调出到Web服务,如果我在代理服务器要求身份验证我想只是使用默认凭据...

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆