Esempio n. 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();
        }
Esempio n. 2
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();
        }