コード例 #1
0
        private void Pman_SendData(object sender, EventArgs e)
        {
            PmanActionRecord pmar = (PmanActionRecord)sender;
            //  RecList.Add(pmar);

            ListViewItem lvi = new ListViewItem()
            {
                Text = pmar.Ordinal.ToString(), Tag = pmar
            };

            lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, pmar.Url));
            lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, pmar.Method));
            lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, pmar.Status));
            lvi.SubItems.Add(new ListViewItem.ListViewSubItem(lvi, pmar.Date.ToString()));
            this.listView1.Items.Add(lvi);
        }
コード例 #2
0
        public void LoadData(PmanActionRecord pmar)
        {
            tbRequest.Text  = string.Empty;
            tbResponse.Text = string.Empty;
            treeView1.Nodes.Clear();

            tbRequest.Text  = "URL: " + pmar.Url;
            tbRequest.Text += Environment.NewLine + "METHOD: " + pmar.Method;
            tbRequest.Text += Environment.NewLine + "Headers:";
            foreach (string k in pmar.Headers.Keys)
            {
                tbRequest.Text += Environment.NewLine + "   " + k + ": " + pmar.Headers[k];
            }
            tbRequest.Text += Environment.NewLine;
            tbRequest.Text += Environment.NewLine + "BODY:";
            try {
                tbRequest.Text += Environment.NewLine + new Classes.JsonFormatter(pmar.Body).Format();
            } catch {
                tbRequest.Text += Environment.NewLine + pmar.Body;
            }

            tbResponse.Text  = "Status: " + pmar.Status;
            tbResponse.Text += Environment.NewLine;
            try {
                tbResponse.Text += Environment.NewLine + new Classes.JsonFormatter(pmar.Response).Format();
            }
            catch {
                tbResponse.Text += pmar.Response;
            }

            try
            {
                LoadJsonToTreeView(this.treeView1, pmar.Response);
            }
            catch { }
        }
コード例 #3
0
        static public string Get(string url, string method, string body)
        {
            _ord++;
            StringBuilder    lup  = new StringBuilder();
            StringBuilder    ldwn = new StringBuilder();
            PmanActionRecord pmar = new PmanActionRecord()
            {
                Date = DateTime.Now, Body = body, Url = BaseUrl + url, Method = method, Ordinal = _ord
            };

            try
            {
                lup.AppendLine(method + "\\");
                pmar.Headers.Add("accept", "application/json;charset=utf-8");
                lup.AppendLine("-H 'accept: application/json;charset=utf-8' \\");
                System.Net.WebRequest req = System.Net.WebRequest.Create(BaseUrl + url);

                req.Method  = method;
                req.Timeout = 1000 * 3600;
                ((System.Net.HttpWebRequest)req).Accept = "application/json;charset=utf-8";
                if (method == "POST" || method == "PUT")
                {
                    req.ContentType   = "application/json";
                    req.ContentLength = body.Length;
                    lup.AppendLine("-H 'content-type: application/json' \\");
                    lup.AppendLine("-H 'content-lenght: " + body.Length.ToString() + "' \\");
                    pmar.Headers.Add("content-type", "application/json");
                    pmar.Headers.Add("content-lenght", body.Length.ToString());
                    System.IO.StreamWriter stOut = new System.IO.StreamWriter(req.GetRequestStream(), System.Text.Encoding.Default);
                    stOut.Write(body);
                    stOut.Close();
                    lup.AppendLine("'" + BaseUrl + url + "'");
                    lup.AppendLine(body);
                }
                else
                {
                    lup.AppendLine("'" + BaseUrl + url + "'");
                }
                OnRequestSend(EventArgs.Empty, lup.ToString());
                System.IO.StreamReader stIn = new System.IO.StreamReader(req.GetResponse().GetResponseStream());
                string strResponse          = stIn.ReadToEnd();
                stIn.Close();



                ldwn.AppendLine(strResponse);
                OnResponseRecieve(EventArgs.Empty, ldwn.ToString());

                pmar.Response = strResponse;
                pmar.Status   = "200 ok";
                OnSendData(EventArgs.Empty, pmar);
                return(strResponse);
            }
            catch (System.Net.WebException exx)
            {
                using (System.Net.WebResponse response = exx.Response)
                {
                    System.Net.HttpWebResponse httpResponse = (System.Net.HttpWebResponse)response;
                    string t = string.Empty;

                    using (System.IO.Stream data = response.GetResponseStream())
                    {
                        t = new System.IO.StreamReader(data).ReadToEnd();
                    }
                    ldwn.Append("Status code: " + exx.Status.ToString());
                    ldwn.Append(t);
                    OnResponseRecieve(EventArgs.Empty, ldwn.ToString());
                    OnError(EventArgs.Empty, t);

                    pmar.Response = t;
                    pmar.Status   = exx.Status.ToString();
                    OnSendData(EventArgs.Empty, pmar);
                    return(t);
                }
            }
        }