A document range that represents a form, and all embedded tags.
Inheritance: DocumentRange
示例#1
0
        /// <summary>
        /// Called by loadContents to load a form on the page.
        /// </summary>
        /// <param name="index">The index to begin loading at.</param>
        /// <param name="tag">The beginning tag.</param>
        protected void LoadForm(int index, Tag tag)
        {
            String method = tag.GetAttributeValue("method");
            String action = tag.GetAttributeValue("action");

            var form = new Form(_page);
            form.Begin = index;
            form.End = FindEndTag(index + 1, tag);

            if ((method == null) || string.Compare(method, "GET", true) == 0)
            {
                form.Method = Form.FormMethod.Get;
            }
            else
            {
                form.Method = Form.FormMethod.Post;
            }

            if (action == null)
            {
                form.Action = new Address(_baseURL);
            }
            else
            {
                form.Action = new Address(_baseURL, action);
            }

            _page.AddContent(form);
            _lastForm = form;
        }
示例#2
0
        /// <summary>
        /// Navigate based on a form. Complete and post the form.
        /// </summary>
        /// <param name="form">The form to be posted.</param>
        /// <param name="submit">The submit button on the form to simulate clicking.</param>
        public void Navigate(Form form, Input submit)
        {
            try
            {
#if logging
                if (logger.IsInfoEnabled)
                {
                    logger.Info("Posting a form");
                }
#endif
                Stream istream;
                Stream ostream;
                Uri targetURL;
                WebRequest http = null;

                if (form.Method == Form.FormMethod.Get)
                {
                    ostream = new MemoryStream();
                }
                else
                {
                    http = WebRequest.Create(form.Action.Url);
                    http.Timeout = 30000;
                    http.ContentType = "application/x-www-form-urlencoded";
                    http.Method = "POST";
                    ostream = http.GetRequestStream();
                }

                // add the parameters if present
                var formData = new FormUtility(ostream, null);
                foreach (DocumentRange dr in form.Elements)
                {
                    if (dr is FormElement)
                    {
                        var element = (FormElement) dr;
                        if ((element == submit) || element.AutoSend)
                        {
                            String name = element.Name;
                            String value = element.Value;
                            if (name != null)
                            {
                                if (value == null)
                                {
                                    value = "";
                                }
                                formData.Add(name, value);
                            }
                        }
                    }
                }

                // now execute the command
                if (form.Method == Form.FormMethod.Get)
                {
                    String action = form.Action.Url.ToString();
                    ostream.Close();
                    action += "?";
                    action += ostream.ToString();
                    targetURL = new Uri(action);
                    http = WebRequest.Create(targetURL);
                    var response = (HttpWebResponse) http.GetResponse();
                    istream = response.GetResponseStream();
                }
                else
                {
                    targetURL = form.Action.Url;
                    ostream.Close();
                    var response = (HttpWebResponse) http.GetResponse();
                    istream = response.GetResponseStream();
                }

                Navigate(targetURL, istream);
                istream.Close();
            }
            catch (IOException e)
            {
                throw new BrowseError(e);
            }
        }
示例#3
0
 protected void LoadForm(int index, Tag tag)
 {
     string str2;
     Form form;
     string attributeValue = tag.GetAttributeValue("method");
     goto Label_00E4;
     Label_0011:
     if (str2 == null)
     {
         form.Action = new Address(this._x1554c0f0264b8597);
     }
     else
     {
         form.Action = new Address(this._x1554c0f0264b8597, str2);
     }
     this._xbbe2f7d7c86e0379.AddContent(form);
     this._xddf51e0bb7096df0 = form;
     if (0 != 0)
     {
         goto Label_00E4;
     }
     if ((((uint) index) - ((uint) index)) <= uint.MaxValue)
     {
         return;
     }
     Label_0057:
     form.Method = Form.FormMethod.Post;
     goto Label_0011;
     Label_007A:
     if (attributeValue != null)
     {
         goto Label_00C9;
     }
     Label_007D:
     form.Method = Form.FormMethod.Get;
     goto Label_0011;
     Label_00C9:
     if (string.Compare(attributeValue, "GET", true) != 0)
     {
         goto Label_0057;
     }
     if (0 == 0)
     {
         goto Label_007D;
     }
     goto Label_007A;
     Label_00E4:
     str2 = tag.GetAttributeValue("action");
     form = new Form(this._xbbe2f7d7c86e0379);
     if (0 == 0)
     {
         if ((((uint) index) & 0) == 0)
         {
             form.Begin = index;
             form.End = this.FindEndTag(index + 1, tag);
         }
         if ((((uint) index) - ((uint) index)) <= uint.MaxValue)
         {
             goto Label_007A;
         }
         goto Label_00C9;
     }
     goto Label_0057;
 }
示例#4
0
 /// <summary>
 /// Navigate to the specified form by performing a submit of that form.
 /// </summary>
 /// <param name="form">The form to be submitted.</param>
 public void Navigate(Form form)
 {
     Navigate(form, null);
 }
示例#5
0
文件: Browser.cs 项目: neismit/emds
 public void Navigate(Form form, Input submit)
 {
     try
     {
         Stream requestStream;
         Uri url;
         FormUtility utility;
         string str3;
         HttpWebResponse response;
         WebRequest request = null;
         goto Label_01D3;
     Label_0007:
         requestStream.Close();
         Stream responseStream = ((HttpWebResponse) request.GetResponse()).GetResponseStream();
     Label_0022:
         this.Navigate(url, responseStream);
     Label_002A:
         responseStream.Close();
         if (0 == 0)
         {
             return;
         }
         if (0 == 0)
         {
             goto Label_0057;
         }
     Label_0036:
         responseStream = response.GetResponseStream();
         goto Label_0022;
     Label_0040:
         if (form.Method == Form.FormMethod.Get)
         {
             goto Label_0081;
         }
         url = form.Action.Url;
         goto Label_0007;
     Label_0057:
         response = (HttpWebResponse) WebRequest.Create(url).GetResponse();
         goto Label_0036;
     Label_0074:
         url = new Uri(str3);
         goto Label_0057;
     Label_0081:
         str3 = form.Action.Url.ToString();
         requestStream.Close();
         str3 = str3 + "?" + requestStream.ToString();
         goto Label_0074;
     Label_00BB:
         if (0x7fffffff == 0)
         {
             goto Label_0074;
         }
         goto Label_0040;
     Label_00C7:
         request.Method = "POST";
         requestStream = request.GetRequestStream();
     Label_00D9:
         utility = new FormUtility(requestStream, null);
         if (0 != 0)
         {
             goto Label_002A;
         }
         using (IEnumerator<DocumentRange> enumerator = form.Elements.GetEnumerator())
         {
             DocumentRange range;
             FormElement element;
             string str;
             string str2;
             goto Label_0109;
         Label_00F7:
             if (element.AutoSend)
             {
                 goto Label_0163;
             }
             goto Label_0109;
         Label_0105:
             if (str != null)
             {
                 goto Label_013B;
             }
         Label_0109:
             if (enumerator.MoveNext())
             {
                 goto Label_016E;
             }
             goto Label_0141;
         Label_0117:
             str2 = "";
             if (0 != 0)
             {
                 goto Label_0163;
             }
         Label_0121:
             utility.Add(str, str2);
             goto Label_0109;
         Label_012E:
             if (range is FormElement)
             {
                 goto Label_017D;
             }
             goto Label_0109;
         Label_013B:
             if (str2 != null)
             {
                 goto Label_0121;
             }
             goto Label_0117;
         Label_0141:
             if (0 == 0)
             {
                 goto Label_0040;
             }
             goto Label_016E;
         Label_0146:
             str2 = element.Value;
             if (0 == 0)
             {
                 goto Label_0105;
             }
             if (-2147483648 != 0)
             {
                 goto Label_016E;
             }
         Label_0159:
             if (element != submit)
             {
                 goto Label_00F7;
             }
         Label_0163:
             str = element.Name;
             goto Label_0146;
         Label_016E:
             range = enumerator.Current;
             if (0 != 0)
             {
                 goto Label_0109;
             }
             if (0 == 0)
             {
                 goto Label_012E;
             }
         Label_017D:
             element = (FormElement) range;
             goto Label_0159;
         }
         goto Label_00BB;
     Label_019F:
         requestStream = new MemoryStream();
         goto Label_00D9;
     Label_01AA:
         request = WebRequest.Create(form.Action.Url);
         request.Timeout = 0x7530;
         request.ContentType = "application/x-www-form-urlencoded";
         goto Label_00C7;
     Label_01D3:
         if (form.Method != Form.FormMethod.Get)
         {
             goto Label_01AA;
         }
         goto Label_019F;
     }
     catch (IOException exception)
     {
         throw new BrowseError(exception);
     }
 }