Microsoft.Protocols.TestSuites.Common.AutoDiscover.SendHttpPostRequest C# (CSharp) Method

SendHttpPostRequest() private static method

Run the Http post method
private static SendHttpPostRequest ( ITestSite site, string userName, string domain, string requestXml, string url, string &responseXml, bool getMAPIURL ) : HttpStatusCode
site ITestSite An instance of interface ITestSite which provides logging, assertions, /// and adapters for test code onto its execution context.
userName string User name used to logon
domain string Domain name
requestXml string the request xml
url string the request send to
responseXml string The response xml
getMAPIURL bool True indicates add headers to get MAPIHTTP url; default value is false
return HttpStatusCode
        private static HttpStatusCode SendHttpPostRequest(ITestSite site, string userName, string domain, string requestXml, string url, out string responseXml, bool getMAPIURL)
        {
            System.Net.ServicePointManager.ServerCertificateValidationCallback =
            new System.Net.Security.RemoteCertificateValidationCallback(Common.ValidateServerCertificate);
            HttpStatusCode httpStatusCode = HttpStatusCode.Created;
            responseXml = null;

            try
            {
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
                request.CookieContainer = new CookieContainer();
                request.Method = "POST";
                request.Accept = "*/*";
                request.ContentType = "text/xml";
                request.Credentials = CredentialCache.DefaultCredentials;
                request.AllowAutoRedirect = false;
                request.KeepAlive = false;

                // Add headers to get MAPIHTTP url                        
                if (getMAPIURL)
                {
                    request.Headers.Add("X-MapiHttpCapability", "2");
                    request.Headers.Add("X-AnchorMailbox", userName + "@" + domain);
                }

                byte[] buffer = Encoding.UTF8.GetBytes(requestXml);
                request.ContentLength = buffer.Length;
                Stream webRequestStream = request.GetRequestStream();
                webRequestStream.Write(buffer, 0, buffer.Length);
                webRequestStream.Flush();
                webRequestStream.Dispose();
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                responseXml = reader.ReadToEnd();
                httpStatusCode = response.StatusCode;
                reader.Close();
                response.Close();

                if (httpStatusCode != HttpStatusCode.OK)
                {
                    site.Assert.Fail("Can't connect the server.");
                }
            }
            catch (WebException e)
            {
                site.Assert.Fail("A WebException happened when connecting the server. The error message is: {0}", e.Message.ToString());
            }

            return httpStatusCode;
        }