本文整理汇总了C#中IWebProxy.IsBypassed方法的典型用法代码示例。如果您正苦于以下问题:C# IWebProxy.IsBypassed方法的具体用法?C# IWebProxy.IsBypassed怎么用?C# IWebProxy.IsBypassed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IWebProxy
的用法示例。
在下文中一共展示了IWebProxy.IsBypassed方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: UpdateAwb
/// <summary>
/// Main program function
/// </summary>
private void UpdateAwb()
{
try
{
proxy = WebRequest.GetSystemWebProxy();
if (proxy.IsBypassed(new Uri("http://en.wikipedia.org")))
proxy = null;
UpdateUI("Getting current AWB and Updater versions", true);
AWBversion();
if ((!updaterUpdate && !awbUpdate) && string.IsNullOrEmpty(AWBWebAddress))
ExitEarly();
else
{
UpdateUI("Creating a temporary directory", true);
CreateTempDir();
UpdateUI("Downloading AWB", true);
GetAwbFromInternet();
UpdateUI("Unzipping AWB to the temporary directory", true);
UnzipAwb();
UpdateUI("Making sure AWB is closed", true);
CloseAwb();
UpdateUI("Copying AWB files from temp to AWB directory...", true);
CopyFiles();
UpdateUI("Update successful", true);
UpdateUI("Cleaning up from update", true);
KillTempDir();
updateSucessful = true;
ReadyToExit();
}
}
catch (AbortException)
{
ReadyToExit();
}
catch (Exception ex)
{
ErrorHandler.Handle(ex);
}
}
示例2: UpdateAwb
/// <summary>
/// Main program function
/// </summary>
private void UpdateAwb()
{
try
{
proxy = WebRequest.GetSystemWebProxy();
if (proxy.IsBypassed(new Uri("http://en.wikipedia.org")))
proxy = null;
updateUI("Getting Current AWB and Updater Versions");
AWBversion();
if ((!updaterUpdate && !awbUpdate) && string.IsNullOrEmpty(AWBWebAddress))
ExitEarly();
else
{
updateUI("Creating a temporary directory");
CreateTempDir();
updateUI("Downloading AWB");
GetAwbFromInternet();
updateUI("Unzipping AWB to the temporary directory");
UnzipAwb();
updateUI("Making sure AWB is closed");
CloseAwb();
updateUI("Copying AWB files from temp to AWB directory");
CopyFiles();
MessageBox.Show("AWB Update Successful", "Update Successful");
updateUI("Starting AWB");
StartAwb();
updateUI("Cleaning up from Update");
KillTempDir();
Application.Exit();
}
}
catch (Exception ex)
{
ErrorHandler.Handle(ex);
}
}
示例3: GetCredentials
/// <summary>
/// Returns an ICredentials instance that the consumer would need in order
/// to properly authenticate to the given Uri.
/// </summary>
public ICredentials GetCredentials(Uri uri, IWebProxy proxy, CredentialType credentialType, bool retrying)
{
if (uri == null)
{
throw new ArgumentNullException("uri");
}
// Capture the original proxy before we do anything
// so that we can re-set it once we get the credentials for the given Uri.
IWebProxy originalProxy = null;
if (proxy != null)
{
// If the current Uri should be bypassed then don't try to get the specific
// proxy but simply capture the one that is given to us
if (proxy.IsBypassed(uri))
{
originalProxy = proxy;
}
// If the current Uri is not bypassed then get a valid proxy for the Uri
// and make sure that we have the credentials also.
else
{
originalProxy = new WebProxy(proxy.GetProxy(uri));
originalProxy.Credentials = proxy.Credentials == null
? null : proxy.Credentials.GetCredential(uri, null);
}
}
try
{
// The cached credentials that we found are not valid so let's ask the user
// until they abort or give us valid credentials.
InitializeCredentialProxy(uri, originalProxy);
return PromptForCredentials(uri);
}
finally
{
// Reset the original WebRequest.DefaultWebProxy to what it was when we started credential discovery.
WebRequest.DefaultWebProxy = originalProxy;
}
}
示例4: RefreshProxy
public static void RefreshProxy()
{
SystemProxy = WebRequest.GetSystemWebProxy();
if (SystemProxy.IsBypassed(new Uri(URL)))
{
SystemProxy = null;
}
}
示例5: FindServicePoint
public static ServicePoint FindServicePoint (Uri address, IWebProxy proxy)
{
if (address == null)
throw new ArgumentNullException ("address");
RecycleServicePoints ();
bool usesProxy = false;
bool useConnect = false;
if (proxy != null && !proxy.IsBypassed(address)) {
usesProxy = true;
bool isSecure = address.Scheme == "https";
address = proxy.GetProxy (address);
if (address.Scheme != "http" && !isSecure)
throw new NotSupportedException ("Proxy scheme not supported.");
if (isSecure && address.Scheme == "http")
useConnect = true;
}
address = new Uri (address.Scheme + "://" + address.Authority);
ServicePoint sp = null;
lock (servicePoints) {
SPKey key = new SPKey (address, useConnect);
sp = servicePoints [key] as ServicePoint;
if (sp != null)
return sp;
if (maxServicePoints > 0 && servicePoints.Count >= maxServicePoints)
throw new InvalidOperationException ("maximum number of service points reached");
string addr = address.ToString ();
#if NET_2_1
int limit = defaultConnectionLimit;
#else
int limit = (int) manager.GetMaxConnections (addr);
#endif
sp = new ServicePoint (address, limit, maxServicePointIdleTime);
sp.Expect100Continue = expectContinue;
sp.UseNagleAlgorithm = useNagle;
sp.UsesProxy = usesProxy;
sp.UseConnect = useConnect;
sp.SetTcpKeepAlive (tcp_keepalive, tcp_keepalive_time, tcp_keepalive_interval);
servicePoints.Add (key, sp);
}
return sp;
}
示例6: ConnectStream
/// <summary>
/// This function will connect a stream to a uri (host and port),
/// negotiating proxies and SSL
/// </summary>
/// <param name="uri"></param>
/// <param name="timeout_ms">Timeout, in ms. 0 for no timeout.</param>
/// <returns></returns>
public static Stream ConnectStream(Uri uri, IWebProxy proxy, bool nodelay, int timeout_ms)
{
IMockWebProxy mockProxy = proxy != null ? proxy as IMockWebProxy : null;
if (mockProxy != null)
return mockProxy.GetStream(uri);
Stream stream;
bool useProxy = proxy != null && !proxy.IsBypassed(uri);
if (useProxy)
{
Uri proxyURI = proxy.GetProxy(uri);
stream = ConnectSocket(proxyURI, nodelay, timeout_ms);
}
else
{
stream = ConnectSocket(uri, nodelay, timeout_ms);
}
try
{
if (useProxy)
{
string line = String.Format("CONNECT {0}:{1} HTTP/1.0", uri.Host, uri.Port);
WriteLine(line, stream);
WriteLine(stream);
ReadHttpHeaders(ref stream, proxy, nodelay, timeout_ms);
}
if (UseSSL(uri))
{
SslStream sslStream = new SslStream(stream, false,
new RemoteCertificateValidationCallback(ValidateServerCertificate), null);
sslStream.AuthenticateAsClient("");
stream = sslStream;
}
return stream;
}
catch
{
stream.Close();
throw;
}
}
示例7: ApiEdit
/// <summary>
/// Creates a new instance of the ApiEdit class
/// </summary>
/// <param name="url">Path to scripts on server</param>
/// <param name="usePHP5">Whether a .php5 extension is to be used</param>
public ApiEdit(string url, bool usePHP5)
: this()
{
if (string.IsNullOrEmpty(url)) throw new ArgumentException("Invalid URL specified", "url");
if (!url.StartsWith("http://")) throw new NotSupportedException("Only editing via HTTP is currently supported");
URL = url;
PHP5 = usePHP5;
ApiURL = URL + "api.php" + (PHP5 ? "5" : "");
Maxlag = 5;
IWebProxy proxy;
if (ProxyCache.TryGetValue(url, out proxy))
{
ProxySettings = proxy;
}
else
{
ProxySettings = WebRequest.GetSystemWebProxy();
if (ProxySettings.IsBypassed(new Uri(url)))
{
ProxySettings = null;
}
ProxyCache.Add(url, ProxySettings);
}
}
示例8: FindServicePoint
public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy)
{
if (address == null)
{
throw new ArgumentNullException("address");
}
var usesProxy = false;
if (proxy != null && !proxy.IsBypassed(address))
{
usesProxy = true;
var isSecure = address.Scheme == Uri.UriSchemeHttps;
address = proxy.GetProxy(address);
if (address.Scheme != Uri.UriSchemeHttp && !isSecure)
{
throw new NotSupportedException("Proxy scheme not supported.");
}
}
var key = MakeQueryString(address, usesProxy);
return _servicePoints.GetOrAdd(key, new Lazy<ServicePoint>(() =>
{
if (_maxServicePoints > 0 && _servicePoints.Count >= _maxServicePoints)
{
throw new InvalidOperationException("maximum number of service points reached");
}
return new ServicePoint(address, _defaultConnectionLimit, key, usesProxy);
}, false)).Value;
}
示例9: FindServicePoint
// If abortState becomes non-zero, the attempt to find a service point has been aborted.
internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
{
if (address==null) {
throw new ArgumentNullException("address");
}
GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());
bool isProxyServicePoint = false;
chain = null;
//
// find proxy info, and then switch on proxy
//
Uri proxyAddress = null;
if (proxy!=null && !address.IsLoopback) {
IAutoWebProxy autoProxy = proxy as IAutoWebProxy;
if (autoProxy != null)
{
chain = autoProxy.GetProxies(address);
// Set up our ability to abort this MoveNext call. Note that the current implementations of ProxyChain will only
// take time on the first call, so this is the only place we do this. If a new ProxyChain takes time in later
// calls, this logic should be copied to other places MoveNext is called.
GlobalLog.Assert(abortDelegate == null, "ServicePointManager::FindServicePoint()|AbortDelegate already set.");
abortDelegate = chain.HttpAbortDelegate;
try
{
Thread.MemoryBarrier();
if (abortState != 0)
{
Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Request aborted before proxy lookup.", exception);
throw exception;
}
if (!chain.Enumerator.MoveNext())
{
GlobalLog.Assert("ServicePointManager::FindServicePoint()|GetProxies() returned zero proxies.");
/*
Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestProhibitedByProxy), WebExceptionStatus.RequestProhibitedByProxy);
GlobalLog.LeaveException("ServicePointManager::FindServicePoint() Proxy prevented request.", exception);
throw exception;
*/
}
proxyAddress = chain.Enumerator.Current;
}
finally
{
abortDelegate = null;
}
}
else if (!proxy.IsBypassed(address))
{
// use proxy support
// rework address
proxyAddress = proxy.GetProxy(address);
}
// null means DIRECT
if (proxyAddress!=null) {
address = proxyAddress;
isProxyServicePoint = true;
}
}
ServicePoint servicePoint = FindServicePointHelper(address, isProxyServicePoint);
GlobalLog.Leave("ServicePointManager::FindServicePoint() servicePoint#" + ValidationHelper.HashString(servicePoint));
return servicePoint;
}
示例10: FindServicePoint
internal static ServicePoint FindServicePoint(Uri address, IWebProxy proxy, out ProxyChain chain, ref HttpAbortDelegate abortDelegate, ref int abortState)
{
if (address == null)
{
throw new ArgumentNullException("address");
}
bool isProxyServicePoint = false;
chain = null;
Uri current = null;
if ((proxy != null) && !address.IsLoopback)
{
IAutoWebProxy proxy2 = proxy as IAutoWebProxy;
if (proxy2 != null)
{
chain = proxy2.GetProxies(address);
abortDelegate = chain.HttpAbortDelegate;
try
{
Thread.MemoryBarrier();
if (abortState != 0)
{
Exception exception = new WebException(NetRes.GetWebStatusString(WebExceptionStatus.RequestCanceled), WebExceptionStatus.RequestCanceled);
throw exception;
}
chain.Enumerator.MoveNext();
current = chain.Enumerator.Current;
}
finally
{
abortDelegate = null;
}
}
else if (!proxy.IsBypassed(address))
{
current = proxy.GetProxy(address);
}
if (current != null)
{
address = current;
isProxyServicePoint = true;
}
}
return FindServicePointHelper(address, isProxyServicePoint);
}
示例11: FindServicePoint
//
// FindServicePoint - Query using an Uri for a given server point
//
/// <include file='doc\ServicePointManager.uex' path='docs/doc[@for="ServicePointManager.FindServicePoint2"]/*' />
/// <devdoc>
/// <para>Findes an existing <see cref='System.Net.ServicePoint'/> or creates a new <see cref='System.Net.ServicePoint'/> to manage communications to the specified <see cref='System.Uri'/>
/// instance.</para>
/// </devdoc>
public static ServicePoint FindServicePoint(Uri address, IWebProxy proxy) {
if (address==null) {
throw new ArgumentNullException("address");
}
GlobalLog.Enter("ServicePointManager::FindServicePoint() address:" + address.ToString());
string tempEntry;
bool isProxyServicePoint = false;
ScavengeIdleServicePoints();
//
// find proxy info, and then switch on proxy
//
if (proxy!=null && !proxy.IsBypassed(address)) {
// use proxy support
// rework address
Uri proxyAddress = proxy.GetProxy(address);
if (proxyAddress.Scheme != Uri.UriSchemeHttps && proxyAddress.Scheme != Uri.UriSchemeHttp) {
Exception exception = new NotSupportedException(SR.GetString(SR.net_proxyschemenotsupported, proxyAddress.Scheme));
GlobalLog.LeaveException("ServicePointManager::FindServicePoint() proxy has unsupported scheme:" + proxyAddress.Scheme.ToString(), exception);
throw exception;
}
address = proxyAddress;
isProxyServicePoint = true;
//
// Search for the correct proxy host,
// then match its acutal host by using ConnectionGroups
// which are located on the actual ServicePoint.
//
tempEntry = MakeQueryString(proxyAddress);
}
else {
//
// Typical Host lookup
//
tempEntry = MakeQueryString(address);
}
//
// lookup service point in the table
//
ServicePoint servicePoint = null;
lock (s_ServicePointTable) {
//
// once we grab the lock, check if it wasn't already added
//
WeakReference servicePointReference = (WeakReference) s_ServicePointTable[tempEntry];
if ( servicePointReference != null ) {
servicePoint = (ServicePoint)servicePointReference.Target;
}
if (servicePoint == null) {
//
// lookup failure or timeout, we need to create a new ServicePoint
//
if (s_MaxServicePoints<=0 || s_ServicePointTable.Count<s_MaxServicePoints) {
//
// Determine Connection Limit
//
int connectionLimit = InternalConnectionLimit;
string schemeHostPort = MakeQueryString(address);
if (ConfigTable.ContainsKey(schemeHostPort) ) {
connectionLimit = (int) ConfigTable[schemeHostPort];
}
// Note: we don't check permissions to access proxy.
// Rather, we should protect proxy property from being changed
servicePoint = new ServicePoint(address, s_MaxServicePointIdleTime, connectionLimit);
servicePointReference = new WeakReference(servicePoint);
// only set this when created, donates a proxy, statt Server
servicePoint.InternalProxyServicePoint = isProxyServicePoint;
s_ServicePointTable[tempEntry] = servicePointReference;
}
else {
Exception exception = new InvalidOperationException(SR.GetString(SR.net_maxsrvpoints));
GlobalLog.LeaveException("ServicePointManager::FindServicePoint() reached the limit count:" + s_ServicePointTable.Count.ToString() + " limit:" + s_MaxServicePoints.ToString(), exception);
throw exception;
}
}
} // lock
//.........这里部分代码省略.........
示例12: RefreshProxy
/// <summary>
/// Refreshs the system proxy.
/// </summary>
public static void RefreshProxy()
{
// no Internet Explorer available on Linux, so GetSystemWebProxy doesn't work, so disable to avoid 60-second timeouts when offline (unit tests etc.)
if(Globals.UsingLinux)
return;
SystemProxy = WebRequest.GetSystemWebProxy();
if (SystemProxy.IsBypassed(new Uri(URL)))
{
SystemProxy = null;
}
}
示例13: ApiEdit
/// <summary>
/// Initializes a new instance of the <see cref="ApiEdit" /> class.
/// </summary>
/// <param name="url">Path to scripts on server</param>
/// <param name="usePHP5">Whether a .php5 extension is to be used</param>
public ApiEdit(string url, bool usePHP5)
: this()
{
if (string.IsNullOrEmpty(url)) throw new ArgumentException("Invalid URL specified", "url");
//if (!url.StartsWith("http://")) throw new NotSupportedException("Only editing via HTTP is currently supported");
URL = url;
PHP5 = usePHP5;
ApiURL = URL + "api.php" + (PHP5 ? "5" : "");
Maxlag = 5;
IWebProxy proxy;
if (ProxyCache.TryGetValue(url, out proxy))
{
ProxySettings = proxy;
}
// GetSystemWebProxy doesn't work under Linux (no IE settings to find) and can cause 60-second timeout, so skip proxy lookup under Linux
else if(!Globals.UsingLinux)
{
ProxySettings = WebRequest.GetSystemWebProxy();
if (ProxySettings.IsBypassed(new Uri(url)))
{
ProxySettings = null;
}
ProxyCache.Add(url, ProxySettings);
}
}