public static CFProxy[] GetProxiesForURL(CFUrl url, CFProxySettings proxySettings) { if (url == null || url.Handle == IntPtr.Zero) { throw new ArgumentNullException("url"); } if (proxySettings == null) { proxySettings = GetSystemProxySettings(); } CFArray array = CopyProxiesForURL(url, proxySettings.Dictionary); if (array == null) { return(null); } CFProxy[] proxies = new CFProxy[array.Count]; for (int i = 0; i < proxies.Length; i++) { CFDictionary dict = new CFDictionary(array[i], false); proxies[i] = new CFProxy(dict); } array.Dispose(); return(proxies); }
public static CFProxy[] GetProxiesForUri(Uri uri, CFProxySettings proxySettings) { if (uri == null) { throw new ArgumentNullException("uri"); } CFUrl url = CFUrl.Create(uri.AbsoluteUri); if (url == null) { return(null); } CFProxy[] proxies = GetProxiesForURL(url, proxySettings); url.Dispose(); return(proxies); }
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++) { Console.WriteLine("CFWebProxy.GetProxy: ProxyType={0}", proxies[i].ProxyType); switch (proxies[i].ProxyType) { case CFProxyType.AutoConfigurationJavaScript: proxy = GetProxyUriFromScript(proxies[i].AutoConfigurationJavaScript, targetUri, out credentials); break; case CFProxyType.AutoConfigurationUrl: proxy = ExecuteProxyAutoConfigurationURL(proxies[i].AutoConfigurationUrl, targetUri, out credentials); 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; Console.WriteLine("CFWebProxy.GetProxy: No proxy should used since type is None. proxyUri set to {0}", proxy); break; } } if (proxy == null) { // no supported proxies for this Uri, fall back to trying to connect to targetUri directly Console.WriteLine("CFWebProxy.GetProxy: No proxies found - fallback to use targetUri directly."); proxy = targetUri; } } else { Console.WriteLine("CFWebProxy.GetProxy: No proxies found."); proxy = targetUri; } } catch (Exception ex) { Console.WriteLine("CFWebProxy.GetProxy: {0}", ex); // ignore errors while retrieving proxy data proxy = targetUri; } if (!userSpecified) { this.credentials = credentials; } Console.WriteLine("CFWebProxy.GetProxy: ProxyUri returned from GetProxy: {0}", proxy); return(proxy); }
public MenuDialogViewController() : base(new RootElement("")) { CFProxySettings proxy0 = CFNetwork.GetSystemProxySettings(); IWebProxy proxy1 = WebRequest.GetSystemWebProxy(); IWebProxy proxy2 = HttpWebRequest.DefaultWebProxy; IWebProxy proxy3 = HttpWebRequest.GetSystemWebProxy(); IWebProxy proxy4 = CFNetwork.GetDefaultProxy(); RootElement root = new RootElement(""); root.UnevenRows = true; Section section = new Section(); CFProxySettings proxySettings = CFNetwork.GetSystemProxySettings(); section.Add(new MultilineElement("HTTPEnable", proxySettings.HTTPEnable.ToString())); section.Add(new MultilineElement("HTTPPort", proxySettings.HTTPPort.ToString())); section.Add(new MultilineElement("HTTPProxy", (proxySettings.HTTPProxy == null) ? "null" : proxySettings.HTTPProxy.ToString())); section.Add(new MultilineElement("ProxyAutoConfigEnable", proxySettings.ProxyAutoConfigEnable.ToString())); section.Add(new MultilineElement("ProxyAutoConfigJavaScript", (proxySettings.ProxyAutoConfigJavaScript == null) ? "null" : proxySettings.ProxyAutoConfigJavaScript.ToString())); section.Add(new MultilineElement("ProxyAutoConfigURLString", (proxySettings.ProxyAutoConfigURLString == null) ? "null" : proxySettings.ProxyAutoConfigURLString.ToString())); root.Add(section); foreach (NSString key in proxySettings.Dictionary.Keys) { section = new Section(key.ToString()); section.Add(new MultilineElement(proxySettings.Dictionary[key].ToString())); root.Add(section); } StyledStringElement sse; section = new Section(); sse = new StyledStringElement("HttpWebRequest"); sse.Tapped += delegate() { Do_HttpWebRequest(); }; section.Add(sse); root.Add(section); section = new Section(); sse = new StyledStringElement("HttpWebRequest DefaultWebProxy()"); sse.Tapped += delegate() { Do_HttpWebRequest_DefaultWebProxy(); }; section.Add(sse); root.Add(section); section = new Section(); sse = new StyledStringElement("WebClient"); sse.Tapped += delegate() { Do_WebClient(); }; section.Add(sse); root.Add(section); section = new Section(); sse = new StyledStringElement("NSData.FromUrl"); sse.Tapped += delegate() { Do_NSData_FromUrl(); }; section.Add(sse); root.Add(section); section = new Section(); sse = new StyledStringElement("NSUrlConnection"); sse.Tapped += delegate() { Do_NSUrlConnection(); }; section.Add(sse); root.Add(section); section = new Section(); sse = new StyledStringElement("DataDownloader"); sse.Tapped += delegate() { Do_DataDownloader(); }; section.Add(sse); root.Add(section); Root = root; }