Exemplo n.º 1
0
 static Uri ExecuteProxyAutoConfigurationURL(IntPtr proxyAutoConfigURL, Uri targetUri, out NetworkCredential credentials)
 {
     CFProxy[] proxies = CFNetwork.ExecuteProxyAutoConfigurationURL(proxyAutoConfigURL, targetUri);
     if (proxies == null)
     {
         Console.WriteLine("CFWebProxy: ExecuteProxyAutoConfigurationURL. No proxies found.");
     }
     else
     {
         Console.WriteLine("CFWebProxy: ExecuteProxyAutoConfigurationURL. Proxies found.");
     }
     return(SelectProxy(proxies, targetUri, out credentials));
 }
Exemplo n.º 2
0
 static Uri GetProxyUriFromScript(IntPtr script, Uri targetUri, out NetworkCredential credentials)
 {
     CFProxy[] proxies = CFNetwork.GetProxiesForAutoConfigurationScript(script, targetUri);
     if (proxies == null)
     {
         Console.WriteLine("CFWebProxy: GetProxyUriFromScript. No proxies found.");
     }
     else
     {
         Console.WriteLine("CFWebProxy: GetProxyUriFromScript. Proxies found.");
     }
     return(SelectProxy(proxies, targetUri, out credentials));
 }
Exemplo n.º 3
0
 public static IWebProxy CreateDefaultProxy()
 {
     if (Platform.IsMacOS)
     {
         IWebProxy defaultProxy = CFNetwork.GetDefaultProxy();
         if (defaultProxy != null)
         {
             return(defaultProxy);
         }
         Console.WriteLine("MonoWebProxy.CreateDefaultProxy: No proxy returned from CFNetwork.GetDefaultProxy");
     }
     else
     {
         throw new Exception("MonoWebProxy.CreateDefaultProxy: Platform.IsMacOS is false");
     }
     throw new Exception("MonoWebProxy.CreateDefaultProxy Not expecting this to be run");
 }
Exemplo n.º 4
0
        static void CheckMacProxy(Uri uri)
        {
            Console.WriteLine("# Mono's CFNetwork");
            var defaultProxy = CFNetwork.GetDefaultProxy();

            if (defaultProxy != null)
            {
                Console.WriteLine("Got default proxy from CFNetwork.GetDefaultProxy");
                var proxyAddress = new Uri(defaultProxy.GetProxy(uri).AbsoluteUri);
                if (string.Equals(proxyAddress.AbsoluteUri, uri.AbsoluteUri))
                {
                    Console.WriteLine("CFNetwork.GetDefaultProxy. ProxyAddress matches request uri. Ignoring proxy uri: '{0}'", proxyAddress);
                }
                else
                {
                    Console.WriteLine("Found proxy from CFNetwork.GetDefaultProxy. Url '{0}'", proxyAddress.AbsoluteUri);
                }
            }
            Console.WriteLine();
        }
Exemplo n.º 5
0
            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;
        }