try
{
Authority authority = new Authority();
System.Net.IWebProxy theProxy = System.Net.WebRequest.DefaultWebProxy;
authority.Proxy = theProxy;
xmlNode = authority.GetUserInfoByNameAndSerialnumber(this.CertName,this.SerialNumber);
authority = null;
}
catch (Exception e)
{
string errorMsg = e.Message;
int count = 3; //三次輸入錯誤則退出
while (count > 0)
{
if (errorMsg.Contains("Proxy")) //如果是因為proxy問題導致exception
{
count--;
try { ProxyAuthenticate proxyAuthenticate = new ProxyAuthenticate(WebProxy.GetDefaultProxy().Address.Host); //ProxyAuthenticate 為自定義的賬密輸入框 if (proxyAuthenticate.ShowDialog() == System.Windows.Forms.DialogResult.OK) { Authority authority = new Authority(); System.Net.IWebProxy theProxy = System.Net.WebRequest.DefaultWebProxy; authority.Proxy = theProxy; authority.Proxy.Credentials = new System.Net.NetworkCredential(proxyAuthenticate.GetUser(),proxyAuthenticate.getpassword()); xmlNode = authority.GetUserInfoByNameAndSerialnumber(this.CertName,this.SerialNumber); authority = null; break; } } catch (Exception ex) { errorMsg = ex.Message; } } else { throw new Exception(errorMsg); } } }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。