public static CFProxy[] GetProxiesForURL(NSUrl url, CFProxySettings proxySettings) { if (url == null) { throw new ArgumentNullException("url"); } if (proxySettings == null) { proxySettings = GetSystemProxySettings(); } using (NSArray array = CopyProxiesForURL(url, proxySettings.Dictionary)) { if (array == null) { return(null); } NSDictionary[] dictionaries = NSArray.ArrayFromHandle <NSDictionary> (array.Handle); if (dictionaries == null) { return(null); } CFProxy[] proxies = new CFProxy [dictionaries.Length]; for (int i = 0; i < dictionaries.Length; i++) { proxies [i] = new CFProxy(dictionaries [i]); } return(proxies); } }
public static CFProxy[] GetProxiesForUri(Uri uri, CFProxySettings proxySettings) { if (uri == null) { throw new ArgumentNullException("uri"); } using (NSUrl url = NSUrl.FromString(uri.AbsoluteUri)) return(GetProxiesForURL(url, proxySettings)); }
public Uri GetProxy(Uri targetUri) { NetworkCredential credentials = null; Uri proxy = null; if (targetUri == null) { throw new ArgumentNullException("targetUri"); } try { CFProxySettings settings = CFNetwork.GetSystemProxySettings(); CFProxy[] proxies = CFNetwork.GetProxiesForUri(targetUri, settings); if (proxies != null) { for (int i = 0; i < proxies.Length && proxy == null; i++) { switch (proxies[i].ProxyType) { case CFProxyType.AutoConfigurationJavaScript: proxy = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri, out credentials); break; case CFProxyType.AutoConfigurationUrl: // unsupported proxy type (requires fetching script from remote url) break; case CFProxyType.HTTPS: case CFProxyType.HTTP: case CFProxyType.FTP: // create a Uri based on the hostname/port/etc info proxy = GetProxyUri(proxies[i], out credentials); break; case CFProxyType.SOCKS: // unsupported proxy type, try the next one break; case CFProxyType.None: // no proxy should be used proxy = targetUri; break; } } if (proxy == null) { // no supported proxies for this Uri, fall back to trying to connect to targetUri directly proxy = targetUri; } } else { proxy = targetUri; } } catch { // ignore errors while retrieving proxy data proxy = targetUri; } if (!userSpecified) { this.credentials = credentials; } return(proxy); }
public void SetProxy (CFProxySettings proxySettings) { if (proxySettings == null) throw new ArgumentNullException ("proxySettings"); SetProperty (_Proxy, proxySettings.Dictionary); }