Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pURL"></param>
        /// <param name="pCookie"></param>
        /// <param name="pSrcIP"></param>
        /// <param name="pUserAgent"></param>
        public Browser(String pURL, String pCookie, String pSrcIP, String pUserAgent)
        {
            InitializeComponent();

            cTask = TaskFacade.getInstance();
            CMB_UserAgent.DataSource    = mUserAgentSettings;
            CMB_UserAgent.SelectedIndex = 1;


            TB_URL.Text     = pURL;
            TB_Cookies.Text = pCookie;
            mCookies        = pCookie;

            mUserAgentCustom            = pUserAgent;
            CMB_UserAgent.SelectedIndex = 0;
            this.Text = "MiniBrowser 0.3";


            if (!String.IsNullOrEmpty(pURL))
            {
                if (!pURL.ToLower().StartsWith("http"))
                {
                    pURL             = String.Format("http://{0}", pURL);
                    this.TB_URL.Text = pURL;
                } // if (!lURL....
            }     // if (!stri...



            /*
             *
             */
            String lURL = this.TB_URL.Text;

            mHeaderData = String.Empty;

            cTask.clearIECache();
            cTask.clearCookies();


            if (CB_Cookies.Checked && TB_Cookies.Text.Length > 0)
            {
                try
                {
                    foreach (String lCookie in TB_Cookies.Text.ToString().Split(';'))
                    {
                        if (lCookie.Length > 0 && lCookie.Contains("="))
                        {
                            Regex    regex      = new Regex("=");
                            String[] substrings = regex.Split(lCookie, 2);

                            InternetSetCookie(lURL, substrings[0], substrings[1]);
                        } // if (lCookie....
                    }     // foreach (s...
                }
                catch (Exception lEx)
                {
                }
            } // if (CB_Cookie...
              //

            if (CB_UserAgent.Checked && TB_UserAgent.Text.Length > 0)
            {
                mHeaderData = "User-Agent: " + TB_UserAgent.Text + "\r\n";
            }
            else
            {
                mHeaderData = String.Format("User-Agent: {0}\r\n", TB_UserAgent.Text);
            }

            if (CB_Cookies.Checked && TB_Cookies.Text.Length > 0)
            {
                mHeaderData += "Cookie: " + TB_Cookies.Text + "\r\n";
            }


            DeleteUrlCacheEntry(lURL);
            cTask.clearIECache();
            cTask.clearCookies();

            UrlMkSetSessionOption(URLMON_OPTION_USERAGENT, TB_UserAgent.Text, TB_UserAgent.Text.Length, 0);
        }