本文整理汇总了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");
}
}
示例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;
}
}
示例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);
}