Esempio n. 1
0
        public void SetModificSession(Fiddler.Session session)
        {
            ChangeEditRuleMode(RuleEditMode.NewRuleMode, null, null);
            tb_urlFilter.Text          = session.fullUrl;
            cb_macthMode.SelectedIndex = 2;

            pictureBox_editHttpFilter.Tag = GetHttpFilter();
            if (tabControl_Modific.SelectedIndex == 0)
            {
                tabControl_Modific.SelectedIndex = 1;
            }
            else if (tabControl_Modific.SelectedIndex == 2)
            {
                tabControl_Modific.SelectedIndex = 3;
            }

            //Request Replace
            tb_requestReplace_uri.Text = session.fullUrl;
            cb_editRequestEdition.Text = ((Fiddler.HTTPHeaders)(session.oRequest.headers)).HTTPVersion;
            cb_editRequestMethod.Text  = session.RequestMethod;
            elv_requsetReplace.ListDataView.Items.Clear();
            foreach (var tempHead in session.RequestHeaders)
            {
                elv_requsetReplace.ListDataView.Items.Add(String.Format("{0}: {1}", tempHead.Name, tempHead.Value));
            }
            rtb_requsetReplace_body.Clear();
            if (session.requestBodyBytes != null)
            {
                if (session.requestBodyBytes.Length > 0)
                {
                    //Encoding tempRequestEncoding = session.GetRequestBodyEncoding() == null ? Encoding.UTF8 : session.GetRequestBodyEncoding();
                    //rtb_requsetReplace_body.Text = tempRequestEncoding.GetString(session.requestBodyBytes);
                    rtb_requsetReplace_body.Text = session.GetRequestBodyAsString();
                }
            }
            MemoryStream tempRequestStream = new MemoryStream();

            if (session.WriteRequestToStream(false, true, true, tempRequestStream))
            {
                byte[] tempRequestBytes = new byte[tempRequestStream.Length];
                tempRequestBytes = tempRequestStream.ToArray();
                //tempRequestStream.ReadAsync(tempRequestBytes, 0, (int)tempRequestStream.Length);
                //tempRequestStream.Position=0;
                //tempRequestStream.Read(tempRequestBytes, 0, (int)tempRequestStream.Length);
                rtb_requestRaw.Clear();
                rtb_requestRaw.Text = Encoding.UTF8.GetString(tempRequestBytes);
            }
            else
            {
                rtb_requestRaw.Clear();
                rtb_requestRaw.Text = "read RequestStream fail";
            }
            tempRequestStream.Close();

            //Response Replace

            MemoryStream tempReponseStream = new MemoryStream();

            if (session.WriteResponseToStream(tempReponseStream, false))
            {
                byte[] tempResponseBytes = new byte[tempReponseStream.Length];
                tempResponseBytes = tempReponseStream.ToArray();
                rawResponseEdit.SetText(Encoding.UTF8.GetString(tempResponseBytes));
            }
            else
            {
                rawResponseEdit.SetText("read ResponseStream fail");
            }
            tempReponseStream.Close();
        }