Esempio n. 1
0
        private void DoPostByHttpVerb()
        {
            string sRequestHeaders = string.Empty;
            string sResult         = string.Empty;
            string sResponeHeaders = string.Empty;

            string sError = string.Empty;

            string sResponseStatusCodeNumber  = string.Empty;
            string sResponseStatusCode        = string.Empty;
            int    iResponseStatusCodeNumber  = 0;
            string sResponseStatusDescription = string.Empty;


            EWSEditor.Logging.EwsTraceListener oETL = new Logging.EwsTraceListener();
            //oETL.Trace("xxxx", "xxxx");


            this.Cursor = Cursors.WaitCursor;
            string sUseVerb = cmboVerb.Text.Trim();

            // http://msdn.microsoft.com/en-us/library/office/bb409286(v=exchg.150).aspx


            List <KeyValuePair <string, string> > oHeadersList = new List <KeyValuePair <string, string> >();

            foreach (DataGridViewRow row in dgvOptions.Rows)
            {
                if (row.Cells[0].Value != null)
                {
                    oHeadersList.Add(new KeyValuePair <string, string>(row.Cells[0].Value.ToString(), row.Cells[1].Value.ToString()));
                }
            }

            if (cmboVerb.Text.Trim().ToUpper() == "GET RESTREPORT")
            {
                oHeadersList.Add(new KeyValuePair <string, string>("DataServiceVersion", "2.0"));
                oHeadersList.Add(new KeyValuePair <string, string>("MaxDataServiceVersion", "2.0"));
                oHeadersList.Add(new KeyValuePair <string, string>("Accept-Language", "EN-US"));
                oHeadersList.Add(new KeyValuePair <string, string>("X-RWS-Version", "2013-V1"));

                sUseVerb = "GET";
            }


            System.Net.WebProxy oWebProxy = null;
            if (this.rdoSpecifyProxySettings.Checked == true)
            {
                oWebProxy = new System.Net.WebProxy(this.txtProxyServerName.Text.Trim(), Convert.ToInt32(this.txtProxyServerPort.Text.Trim()));

                // TODO: If space is found for the other proxy settins on the window then add them and use the code below.  You can copy the fields from the GlobalOptionsDialog.cs form.
                //oWebProxy.BypassProxyOnLocal = this.chkBypassProxyForLocalAddress.Checked;
                //if (this.rdoOverrideProxyCredentials.Checked == true)
                //{

                //    if (this.txtProxyServerUser.Text.Trim().Length == 0)
                //    {
                //        oWebProxy.UseDefaultCredentials = true;
                //    }
                //    else
                //    {
                //        if (this.txtProxyServerDomain.Trim().Length == 0)
                //            oWebProxy.Credentials = new NetworkCredential(this.txtProxyServerUser.Text.Trim(), this.txtProxyServerPassword.Text.Trim());
                //        else
                //            oWebProxy.Credentials = new NetworkCredential(this.txtProxyServerUser.Text.Trim(), this.txtProxyServerPassword.Text.Trim(), this.txtProxyServerDomain.Text.Trim());
                //    }
                //}
                //else
                //{
                //    oWebProxy.UseDefaultCredentials = true;
                //}
            }

            bool bRet = false;

            DateTime  dtStart    = DateTime.Now;
            Stopwatch oStopwatch = new Stopwatch();

            oStopwatch.Start();

            bRet = EWSEditor.Common.HttpHelper.HtppCall(
                sUseVerb,
                txtUrl.Text.Trim(),
                cmboContentType.Text,
                cmboAuthentication.Text,
                txtUser.Text.Trim(),
                txtPassword.Text.Trim(),
                txtDomain.Text.Trim(),
                oHeadersList,
                oWebProxy,
                txtRequest.Text,
                //txtProxyServer.Text,
                //txtProxyPort.Text,
                (int)numericUpDownTimeoutSeconds.Value,
                chkPragmaNocache.Checked,
                chkTranslateF.Checked,
                chkAllowRedirect.Checked,
                cmboUserAgent.Text,
                ref sRequestHeaders,
                ref sResult,
                ref sResponeHeaders,
                ref sError,
                ref sResponseStatusCode,
                ref iResponseStatusCodeNumber,
                ref sResponseStatusDescription
                );

            DateTime dtEnd = DateTime.Now;

            oStopwatch.Stop();
            TimeSpan oTimeSpan = oStopwatch.Elapsed;
            string   sElapsed  = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               oTimeSpan.Hours,
                                               oTimeSpan.Minutes,
                                               oTimeSpan.Seconds,
                                               oTimeSpan.Milliseconds / 10);

            string sResultOrigional = sResult;

            sResult          = SerialHelper.TryRestoreCrLfAndIndents(sResult);
            txtResponse.Text = sResult;

            // Logging

            if (chkLogCalls.Checked)
            {
                oETL.Trace("EwsRequestHttpHeaders", EWSPostLogEntry(sRequestHeaders, "EwsRequestHttpHeaders"));
                oETL.Trace("EwsRequestHttpBody", EWSPostLogEntry(txtRequest.Text, "EwsRequestHttpBody"));

                oETL.Trace("EwsResponseHttpHeaders", EWSPostLogEntry(sResponeHeaders, "EwsResponseHttpHeaders"));
                oETL.Trace("EwsResponseHttpBody", EWSPostLogEntry(sResultOrigional, "EwsResponseHttpBody"));

                //Debug this section
            }



            string utf16Line = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
            string utf8Line  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            string sCopy     = sResult.TrimStart();

            if (sCopy.StartsWith(utf16Line))
            {
                //sCopy = sCopy.Remove(0, utf16Line.Length);

                sCopy = sCopy.Replace(utf16Line, utf8Line + "\r\n<!-- Note: EwsEditor has replaced the \"utf-16\" text in the first line with\"utf-8\" in order for the XML to render in the response web control. -->");
                //sCopy = sCopy.TrimStart();
            }

            wbResponse.DocumentText = sCopy;
            txtResponse.Text        = sCopy;


            StringBuilder oSB = new StringBuilder();

            oSB.AppendFormat("Start: {0}  End: {1}  Timespan: {2}:\r\n\r\n",
                             dtStart.ToString(),
                             dtEnd.ToString(),
                             sElapsed
                             );

            if (bRet != true)
            {
                oSB.AppendFormat("Failed:\r\n");
                oSB.AppendFormat("    Error: {0}\r\n\r\n", sError);
            }

            oSB.AppendFormat("ResponseStatusCode: {0}\r\n\r\n", sResponseStatusCode);
            oSB.AppendFormat("ResponseCodeNumber: {0}\r\n\r\n", iResponseStatusCodeNumber);
            oSB.AppendFormat("ResponseStatusDescription: {0}\r\n\r\n", sResponseStatusDescription);
            //oSB.AppendFormat("Result: {0}\r\n", sResult);



            oSB.AppendFormat("Request Headers: \r\n{0}\r\n", sRequestHeaders);
            oSB.AppendFormat("Response Headers: \r\n{0}\r\n", sResponeHeaders);

            oSB.AppendLine(CheckResponseForOddCharacters(sResult));

            txtResponseSummary.Text = oSB.ToString();


            this.Cursor = Cursors.Default;
        }
Esempio n. 2
0
        private void DoRawPost()
        {
            string sRequest = string.Empty;

            sRequest = txtRequest.Text;

            System.Net.WebProxy oWebProxy = null;
            if (this.rdoSpecifyProxySettings.Checked == true)
            {
                oWebProxy = new System.Net.WebProxy(this.txtProxyServerName.Text.Trim(), Convert.ToInt32(this.txtProxyServerPort.Text.Trim()));
            }

            DateTime  dtStart    = DateTime.Now;
            Stopwatch oStopwatch = new Stopwatch();

            oStopwatch.Start();

            HttpWebRequest oHttpWebRequest = EWSEditor.Common.HttpHelper.EntirePostRequestToHttpWebRequest(
                txtRequest.Text,
                cmboAuthentication.Text,
                txtUser.Text.Trim(),
                txtPassword.Text.Trim(),
                txtDomain.Text.Trim(),
                oWebProxy
                );


            bool   bRet                       = false;
            string sRequestHeaders            = string.Empty;
            string sResult                    = string.Empty;
            string sResponeHeaders            = string.Empty;
            string sError                     = string.Empty;
            string sResponseStatusCode        = string.Empty;
            int    iResponseStatusCodeNumber  = 0;
            string sResponseStatusDescription = string.Empty;

            bRet = EWSEditor.Common.HttpHelper.DoHttpWebRequest(
                ref oHttpWebRequest,

                ref sRequestHeaders,
                ref sResult,
                ref sResponeHeaders,
                ref sError,
                ref sResponseStatusCode,
                ref iResponseStatusCodeNumber,
                ref sResponseStatusDescription
                );

            DateTime dtEnd = DateTime.Now;

            oStopwatch.Stop();
            TimeSpan oTimeSpan = oStopwatch.Elapsed;
            string   sElapsed  = String.Format("{0:00}:{1:00}:{2:00}.{3:00}",
                                               oTimeSpan.Hours,
                                               oTimeSpan.Minutes,
                                               oTimeSpan.Seconds,
                                               oTimeSpan.Milliseconds / 10);


            sResult          = SerialHelper.TryRestoreCrLfAndIndents(sResult);
            txtResponse.Text = sResult;

            // blank
            //wbResponse.DocumentText = sResult;

            // blank...
            // string sFile = CreateTempFile(sResult, "xml");
            // wbResponse.Navigate(sFile);

            // same...
            //byte[] bytes = Encoding.UTF8.GetBytes(sResult);
            //MemoryStream oMemoryStream = new MemoryStream();
            //oMemoryStream.Write(bytes, 0, bytes.Length);
            //oMemoryStream.Position = 0;
            //wbResponse.DocumentStream = oMemoryStream;

            // Note:  If the browser or browser control sees whats inteh utf16Line line the it will error and not render.
            // So as a work-around for now the code wills trip that line just for ie control rendering.
            string utf16Line = "<?xml version=\"1.0\" encoding=\"utf-16\"?>";
            string utf8Line  = "<?xml version=\"1.0\" encoding=\"utf-8\"?>";
            string sCopy     = sResult.TrimStart();

            if (sCopy.StartsWith(utf16Line))
            {
                sCopy = sCopy.Remove(0, utf16Line.Length);
                sCopy = sCopy.TrimStart();
            }
            if (sCopy.StartsWith(utf8Line))
            {
                sCopy = sCopy.Remove(0, utf8Line.Length);
                sCopy = sCopy.TrimStart();
            }

            string sFile = CreateTempFile(sCopy, "xml");

            wbResponse.Navigate(sFile);
            wbResponse.DocumentText = sCopy;



            StringBuilder oSB = new StringBuilder();

            oSB.AppendFormat("Start: {0}  End: {1}  Timespan: {2}\r\n\r\n",
                             dtStart.ToString(),
                             dtEnd.ToString(),
                             sElapsed
                             );

            if (bRet != true)
            {
                oSB.AppendFormat("Failed:\r\n");
                oSB.AppendFormat("    Error: {0}\r\n\r\n", sError);
            }

            oSB.AppendFormat("ResponseStatusCode: {0}\r\n\r\n", sResponseStatusCode);
            oSB.AppendFormat("ResponseCodeNumber: {0}\r\n\r\n", iResponseStatusCodeNumber);
            oSB.AppendFormat("ResponseStatusDescription: {0}\r\n\r\n", sResponseStatusDescription);
            //oSB.AppendFormat("Result: {0}\r\n", sResult);

            oSB.AppendFormat("Request Headers: \r\n{0}\r\n", sRequestHeaders);
            oSB.AppendFormat("Response Headers: \r\n{0}\r\n", sResponeHeaders);

            oSB.AppendLine(CheckResponseForOddCharacters(sResult));

            txtResponseSummary.Text = oSB.ToString();


            this.Cursor = Cursors.Default;
        }