当前位置: 首页>>代码示例>>C#>>正文


C# WebProxy.GetProxy方法代码示例

本文整理汇总了C#中System.Net.WebProxy.GetProxy方法的典型用法代码示例。如果您正苦于以下问题:C# WebProxy.GetProxy方法的具体用法?C# WebProxy.GetProxy怎么用?C# WebProxy.GetProxy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.WebProxy的用法示例。


在下文中一共展示了WebProxy.GetProxy方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: BypassArrayList

		public void BypassArrayList ()
		{
			Uri proxy1 = new Uri ("http://proxy.contoso.com");
			Uri proxy2 = new Uri ("http://proxy2.contoso.com");

			WebProxy p = new WebProxy (proxy1, true);
			p.BypassArrayList.Add ("http://proxy2.contoso.com");
			p.BypassArrayList.Add ("http://proxy2.contoso.com");
			Assert.AreEqual (2, p.BypassList.Length, "#1");
			Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.google.com")), "#2");
			Assert.IsTrue (p.IsBypassed (proxy2), "#3");
			Assert.AreEqual (proxy2, p.GetProxy (proxy2), "#4");

			p.BypassArrayList.Add ("?^[email protected]#$%^&}{][");
			Assert.AreEqual (3, p.BypassList.Length, "#10");
			try {
				Assert.IsTrue (!p.IsBypassed (proxy2), "#11");
				Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.x.com")), "#12");
				Assert.AreEqual (proxy1, p.GetProxy (proxy2), "#13");
				// hmm... although #11 and #13 succeeded before (#3 resp. #4), 
				// it now fails to bypass, and the IsByPassed and GetProxy 
				// methods do not fail.. so when an illegal regular 
				// expression is added through this property it's ignored. 
				// probably an ms.net bug?? :(
			} catch (ArgumentException) {
				Assert.Fail ("#15: illegal regular expression");
			}
		}
开发者ID:nlhepler,项目名称:mono,代码行数:28,代码来源:WebProxyTest.cs

示例2: ValidateProxyFields

        private bool ValidateProxyFields()
        {
            // we'll validate proxy as well
            //var protocol = cmbProtocol.SelectedItem.ToString();
            var host = txtProxyHost.Text;
            var port = txtProxyPort.Text;

            try
            {
                var proxyAddress = string.Format("http://{0}:{1}/", host, port);
                var proxy = new WebProxy(proxyAddress, true);
                proxy.GetProxy(new Uri("http://www.google.com"));
                return true;
            }
            catch (Exception e)
            {
                MessageBox.Show("Invalid proxy, make sure the host and port are valid!", "Invalid proxy");
                btnSave.DialogResult = DialogResult.None;
                return false;
            }
        }
开发者ID:mikkoj,项目名称:nocs,代码行数:21,代码来源:Preferences.cs

示例3: ProxyTest

 public void ProxyTest()
 {
     var target = new FeedConfigItem { ProxyHost = "1.2.3.4", ProxyPass = "ProxyPassword", ProxyType = HttpProxyHelper.ProxyType.Custom, ProxyUser = "proxydomain\\proxyusername", ProxyAuth = true, ProxyPort = 3848 };
     IWebProxy expected = new WebProxy { Address = new Uri("http://1.2.3.4:3848"), Credentials = new NetworkCredential("proxyusername", "ProxyPassword", "proxydomain") };
     var actual = target.Proxy;
     Assert.AreEqual(expected.GetProxy(new Uri("http://www.google.com")), actual.GetProxy(new Uri("http://www.google.com")));
     Assert.AreEqual(expected.Credentials.GetCredential(new Uri("http://www.google.com"), "").Domain,
                     actual.Credentials.GetCredential(new Uri("http://www.google.com"), "").Domain);
     Assert.AreEqual(expected.Credentials.GetCredential(new Uri("http://www.google.com"), "").UserName,
                     actual.Credentials.GetCredential(new Uri("http://www.google.com"), "").UserName);
     Assert.AreEqual(expected.Credentials.GetCredential(new Uri("http://www.google.com"), "").Password,
                     actual.Credentials.GetCredential(new Uri("http://www.google.com"), "").Password);
 }
开发者ID:growse,项目名称:Feedling,代码行数:13,代码来源:FeedConfigItemTest.cs


注:本文中的System.Net.WebProxy.GetProxy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。