Пример #1
0
        private void GETRequest()
        {
            // ini form
            RequestForm form = new RequestForm();

            for (int i = 0; i < 4; i++)
            {
                if (textBoxesNamesVaritables[i].Text.Length > 0)
                {
                    if (textBoxesValuesVaritables[i].Text.Length > 0)
                    {
                        // generating form data
                        RequestFormElement formElement = new RequestFormElement(textBoxesNamesVaritables[i].Text, textBoxesValuesVaritables[i].Text);
                        form.Add(formElement);
                        formElement.Dispose();
                    }
                }
            }

            // start sending response
            Stopwatch sw = new Stopwatch();

            ECHOBox.Text = "WAIT...";
            sw.Start();
            string html = string.Empty;

            string url = form.GenerateGETRequest(TargetURLPole.Text);



            HttpWebRequest request = null;

            try
            {
                request = (HttpWebRequest)WebRequest.Create(url);
            }

            catch (Exception e)
            {
                MessageBox.Show("Ошибка отправки запроса: Текст ошибки: " + e.Message, "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            request.AutomaticDecompression = DecompressionMethods.GZip;

            using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
                using (Stream stream = response.GetResponseStream())
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        html = reader.ReadToEnd();
                    }
            sw.Stop();
            TimeWaitText.Text = "Time milliseconds: " + sw.ElapsedMilliseconds;
            ECHOBox.Text      = html;
            form.Dispose();
        }
Пример #2
0
        /// <summary>
        /// removing data with element
        /// </summary>
        /// <param name="formElement">element target</param>
        public void Remove(RequestFormElement formElement)
        {
            try
            {
                data.Remove(formElement.name);
            }

            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Пример #3
0
        private void POSTRequest()
        {
            // ini form
            RequestForm form = new RequestForm();

            for (int i = 0; i < 4; i++)
            {
                if (textBoxesNamesVaritables[i].Text.Length > 0)
                {
                    if (textBoxesValuesVaritables[i].Text.Length > 0)
                    {
                        // generating form data
                        RequestFormElement formElement = new RequestFormElement(textBoxesNamesVaritables[i].Text, textBoxesValuesVaritables[i].Text);
                        form.Add(formElement);
                        formElement.Dispose();
                    }
                }
            }
            // start sending response
            Stopwatch sw = new Stopwatch();

            ECHOBox.Text = "WAIT...";
            sw.Start();
            HttpClient client   = new HttpClient();
            var        content  = new FormUrlEncodedContent(form.GetData());
            var        response = client.PostAsync(TargetURLPole.Text, content).Result;

            // reading body site
            var contents = response.Content.ReadAsStringAsync().Result;

            // get echo
            ECHOBox.Text = contents;
            sw.Stop();
            TimeWaitText.Text = "Time milliseconds: " + sw.ElapsedMilliseconds;
            form.Dispose();
        }
Пример #4
0
 /// <summary>
 /// add element data in dictory with RequestFormElement
 /// </summary>
 /// <param name="formElement">element</param>
 public void Add(RequestFormElement formElement)
 {
     data.Add(formElement.name, formElement.value);
 }