本文整理汇总了C#中System.Net.WebProxy.IsBypassed方法的典型用法代码示例。如果您正苦于以下问题:C# WebProxy.IsBypassed方法的具体用法?C# WebProxy.IsBypassed怎么用?C# WebProxy.IsBypassed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.WebProxy
的用法示例。
在下文中一共展示了WebProxy.IsBypassed方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: ShouldProxyBeBypassed
public bool ShouldProxyBeBypassed(HttpProxySettings proxySettings, HttpUri url)
{
//We are utilising the WebProxy implementation here to save us having to reimplement it. This way we use Microsofts implementation
var proxy = new WebProxy(proxySettings.Host + ":" + proxySettings.Port, proxySettings.BypassLocalAddress, proxySettings.BypassListAsArray);
return proxy.IsBypassed((Uri)url);
}
示例3: SelectCustomProxy
/// <summary>
/// Метод формирования нестандартного прокси из параметров
/// </summary>
/// <param name="uri"></param>
/// <param name="addrDefinition"></param>
/// <param name="bypassDefinition"></param>
/// <returns></returns>
public static WebProxy SelectCustomProxy(Uri uri, string addrDefinition, string bypassDefinition) {
var defs = ProxyRecord.Parse(addrDefinition);
var def = defs.FirstOrDefault(_ => _.TargetScheme.ToUpperInvariant() == uri.Scheme.ToUpperInvariant());
if (null == def) {
def = defs.FirstOrDefault(_ => _.TargetScheme=="*");
}
if (null == def) return null;
var proxy = new WebProxy(
def.Uri,
true, null,
def.Credentials);
if (!string.IsNullOrWhiteSpace(bypassDefinition))
{
proxy.BypassList = bypassDefinition.SmartSplit(false, true, ' ').ToArray();
}
if (proxy.IsBypassed(uri)) return null;
return proxy;
}
示例4: PostRequest
public static string PostRequest(string url, WebHeaderCollection headers)
{
var responseFromServer = "";
ServicePointManager.Expect100Continue = false;
WebProxy myProxy = new WebProxy();
myProxy.IsBypassed(new Uri(url));
var request = (HttpWebRequest) WebRequest.Create(url);
request.Proxy = myProxy;
request.Method = "POST";
request.ContentType = "text/plain; charset=UTF-8";
request.Referer = Parse.BET365_HOME + "/";
request.Headers.Add("Origin", Parse.BET365_HOME);
request.UserAgent = Parse.USER_AGENT;
request.Accept = "*/*";
request.AutomaticDecompression = DecompressionMethods.GZip;
request.KeepAlive = true;
request.ContentLength = 0;
request.Headers.Add(headers);
request.Timeout = 1500;
using (var response = (HttpWebResponse)request.GetResponse())
{
using (var dataStream = response.GetResponseStream())
{
Debug.Assert(dataStream != null, "dataStream != null");
using (BufferedStream buffer = new BufferedStream(dataStream))
{
using (StreamReader readerStream = new StreamReader(buffer))
{
responseFromServer = readerStream.ReadToEnd();
readerStream.Close();
}
buffer.Close();
}
response.Close();
dataStream.Close();
}
}
return responseFromServer;
}
示例5: IsByPassed_Host_Null
public void IsByPassed_Host_Null ()
{
WebProxy p = new WebProxy ("http://proxy.contoso.com", true);
try {
p.IsBypassed (null);
Assert.Fail ("#A1");
#if NET_2_0
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNotNull (ex.ParamName, "#A4");
Assert.AreEqual ("host", ex.ParamName, "#A5");
Assert.IsNull (ex.InnerException, "#A6");
}
#else
} catch (NullReferenceException) {
示例6: IsByPassed_Address_Null
public void IsByPassed_Address_Null ()
{
WebProxy p = new WebProxy ((Uri) null, false);
Assert.IsTrue (p.IsBypassed (new Uri ("http://www.google.com")), "#1");
p = new WebProxy ((Uri) null, true);
Assert.IsTrue (p.IsBypassed (new Uri ("http://www.google.com")), "#2");
}
示例7: IsByPassed
public void IsByPassed ()
{
WebProxy p = new WebProxy ("http://proxy.contoso.com", true);
Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.google.com")), "#1");
Assert.IsTrue (p.IsBypassed (new Uri ("http://localhost/index.html")), "#2");
Assert.IsTrue (p.IsBypassed (new Uri ("http://localhost:8080/index.html")), "#3");
Assert.IsTrue (p.IsBypassed (new Uri ("http://loopback:8080/index.html")), "#4");
Assert.IsTrue (p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")), "#5");
Assert.IsTrue (p.IsBypassed (new Uri ("http://webserver/index.html")), "#6");
Assert.IsTrue (!p.IsBypassed (new Uri ("http://webserver.com/index.html")), "#7");
p = new WebProxy ("http://proxy.contoso.com", false);
Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.google.com")), "#11");
Assert.IsTrue (p.IsBypassed (new Uri ("http://localhost/index.html")), "#12: lamespec of ms.net");
Assert.IsTrue (p.IsBypassed (new Uri ("http://localhost:8080/index.html")), "#13: lamespec of ms.net");
Assert.IsTrue (p.IsBypassed (new Uri ("http://loopback:8080/index.html")), "#14: lamespec of ms.net");
Assert.IsTrue (p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")), "#15: lamespec of ms.net");
Assert.IsTrue (!p.IsBypassed (new Uri ("http://webserver/index.html")), "#16");
p.BypassList = new string [] { "google.com", "contoso.com" };
Assert.IsTrue (p.IsBypassed (new Uri ("http://www.google.com")), "#20");
Assert.IsTrue (p.IsBypassed (new Uri ("http://www.GOOGLE.com")), "#21");
Assert.IsTrue (p.IsBypassed (new Uri ("http://www.contoso.com:8080/foo/bar/index.html")), "#22");
Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.contoso2.com:8080/foo/bar/index.html")), "#23");
Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.foo.com:8080/contoso.com.html")), "#24");
p.BypassList = new string [] { "https" };
Assert.IsTrue (!p.IsBypassed (new Uri ("http://www.google.com")), "#30");
Assert.IsTrue (p.IsBypassed (new Uri ("https://www.google.com")), "#31");
}
示例8: SelectSystemProxy
/// <summary>
/// Метод формирования системного прокси
/// </summary>
/// <param name="uri"></param>
/// <param name="bypassDefinition"></param>
/// <returns></returns>
/// <exception cref="NotImplementedException"></exception>
public static WebProxy SelectSystemProxy(Uri uri, string bypassDefinition) {
if (WebRequest.DefaultWebProxy.IsBypassed(uri)) return null;
var proxy = new WebProxy(
WebRequest.DefaultWebProxy.GetProxy(uri).ToString(),
true,null,
CredentialCache.DefaultCredentials);
if (!string.IsNullOrWhiteSpace(bypassDefinition)) {
proxy.BypassList = bypassDefinition.SmartSplit(false, true, ' ').ToArray();
}
//second check - bypass list updated
if (proxy.IsBypassed(uri)) return null;
return proxy;
}
示例9: IsByPassed_Host_Null
public void IsByPassed_Host_Null ()
{
WebProxy p = new WebProxy ("http://proxy.contoso.com", true);
try {
p.IsBypassed (null);
Assert.Fail ("#A1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#A2");
Assert.IsNotNull (ex.Message, "#A3");
Assert.IsNotNull (ex.ParamName, "#A4");
Assert.AreEqual ("host", ex.ParamName, "#A5");
Assert.IsNull (ex.InnerException, "#A6");
}
p = new WebProxy ((Uri) null);
try {
p.IsBypassed (null);
Assert.Fail ("#B1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#B2");
Assert.IsNotNull (ex.Message, "#B3");
Assert.IsNotNull (ex.ParamName, "#B4");
Assert.AreEqual ("host", ex.ParamName, "#B5");
Assert.IsNull (ex.InnerException, "#B6");
}
p = new WebProxy ((Uri) null, true);
try {
p.IsBypassed (null);
Assert.Fail ("#C1");
} catch (ArgumentNullException ex) {
Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#C2");
Assert.IsNotNull (ex.Message, "#C3");
Assert.IsNotNull (ex.ParamName, "#C4");
Assert.AreEqual ("host", ex.ParamName, "#C5");
Assert.IsNull (ex.InnerException, "#C6");
}
}
示例10: DownloadFile
public void DownloadFile(string symbol)
{
var symbolName = symbol;
if (symbol[0] == '$')
symbolName = '^' + symbol.Substring(1);
Console.WriteLine("Getting " + symbolName);
var url = "http://ichart.finance.yahoo.com/table.csv?";
var urlParams = string.Format("a={0}&b={1}&c={2}&d={3}&e={4}&f={5}&s={6}&g=d&ignore=.csv",
1, 1, 2000, now.Month, now.Day, now.Year, symbolName);
url += urlParams;
int i = 0;
while(i < 3) // 3 Retries
{
try
{
using (var client = new WebClient())
{
var myProxy = new WebProxy();
myProxy.IsBypassed(new Uri(url));
client.Proxy = myProxy;
client.DownloadFile(url, dataPath + "\\" + symbolName + ".csv");
}
break;
}
catch (WebException e)
{
Debug.Print(e.Message);
i++;
Thread.Sleep(2000*i);
}
catch (Exception e)
{
Debug.Print(e.Message);
i = 3;
break;
}
}
// Timedout or other unrecoverable error
if (i == 3)
{
Interlocked.Increment(ref missCounter);
Console.WriteLine("Unable to fetch data for stock: " + symbolName);
}
}
示例11: IsByPassed
public void IsByPassed ()
{
WebProxy p = new WebProxy ("http://proxy.contoso.com", true);
Assertion.Assert ("#1", !p.IsBypassed (new Uri ("http://www.google.com")));
Assertion.Assert ("#2", p.IsBypassed (new Uri ("http://localhost/index.html")));
Assertion.Assert ("#3", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));
Assertion.Assert ("#4", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));
Assertion.Assert ("#5", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));
Assertion.Assert ("#6", p.IsBypassed (new Uri ("http://webserver/index.html")));
Assertion.Assert ("#7", !p.IsBypassed (new Uri ("http://webserver.com/index.html")));
try {
p.IsBypassed (null);
Assertion.Fail ("#8 not spec'd, but should follow ms.net implementation");
} catch (NullReferenceException) {}
p = new WebProxy ("http://proxy.contoso.com", false);
Assertion.Assert ("#11", !p.IsBypassed (new Uri ("http://www.google.com")));
Assertion.Assert ("#12: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost/index.html")));
Assertion.Assert ("#13: lamespec of ms.net", p.IsBypassed (new Uri ("http://localhost:8080/index.html")));
Assertion.Assert ("#14: lamespec of ms.net", p.IsBypassed (new Uri ("http://loopback:8080/index.html")));
Assertion.Assert ("#15: lamespec of ms.net", p.IsBypassed (new Uri ("http://127.0.0.01:8080/index.html")));
Assertion.Assert ("#16", !p.IsBypassed (new Uri ("http://webserver/index.html")));
p.BypassList = new string [] { "google.com", "contoso.com" };
Assertion.Assert ("#20", p.IsBypassed (new Uri ("http://www.google.com")));
Assertion.Assert ("#21", p.IsBypassed (new Uri ("http://www.GOOGLE.com")));
Assertion.Assert ("#22", p.IsBypassed (new Uri ("http://www.contoso.com:8080/foo/bar/index.html")));
Assertion.Assert ("#23", !p.IsBypassed (new Uri ("http://www.contoso2.com:8080/foo/bar/index.html")));
Assertion.Assert ("#24", !p.IsBypassed (new Uri ("http://www.foo.com:8080/contoso.com.html")));
p.BypassList = new string [] { "https" };
Assertion.Assert ("#30", !p.IsBypassed (new Uri ("http://www.google.com")));
Assertion.Assert ("#31", p.IsBypassed (new Uri ("https://www.google.com")));
}