Beispiel #1
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;
        }