Microsoft.Protocols.TestSuites.Common.MapiHttpAdapter.SendMAPIHttpRequest C# (CSharp) Method

SendMAPIHttpRequest() public static method

The method to send MAPIHTTP request to the server.
public static SendMAPIHttpRequest ( ITestSite site, string mailStoreUrl, string userName, string domain, string password, IRequestBody requestBody, string requestType, CookieCollection cookies ) : HttpWebResponse
site ITestSite An instance of interface ITestSite which provides logging, assertions, /// and adapters for test code onto its execution context.
mailStoreUrl string Mail store url.
userName string The user which connects the server.
domain string The domain of the user.
password string The password for the user.
requestBody IRequestBody The MAPIHTTP request body.
requestType string The MAPIHTTP request type.
cookies System.Net.CookieCollection Cookie container for client.
return System.Net.HttpWebResponse
        public static HttpWebResponse SendMAPIHttpRequest(ITestSite site, string mailStoreUrl, string userName, string domain, string password, IRequestBody requestBody, string requestType, CookieCollection cookies)
        {
            HttpWebResponse response = null;

            System.Net.ServicePointManager.ServerCertificateValidationCallback =
            new System.Net.Security.RemoteCertificateValidationCallback(Common.ValidateServerCertificate);
            HttpWebRequest request = WebRequest.Create(mailStoreUrl) as HttpWebRequest;
            request.KeepAlive = true;
            request.CookieContainer = new CookieContainer();
            request.Method = "POST";
            request.ProtocolVersion = HttpVersion.Version11;
            request.Credentials = new System.Net.NetworkCredential(userName, password, domain);
            request.ContentType = "application/mapi-http";
            request.Accept = "application/mapi-http";
            request.Connection = string.Empty;

            byte[] buffer = null;
            if (requestBody != null)
            {
                buffer = requestBody.Serialize();
                request.ContentLength = buffer.Length;
            }
            else
            {
                request.ContentLength = 0;
            }

            request.Headers.Add("X-ClientInfo", "{A7A47AAD-233C-412B-9D10-DDE9108FEBD7}-5");
            request.Headers.Add("X-RequestId", "{16AC2587-EED8-48EB-8A7B-D48558B68BD7}:1");
            request.Headers.Add("X-ClientApplication", "Outlook/15.00.0856.000");
            request.Headers.Add("X-RequestType", requestType);
            if (cookies != null && cookies.Count > 0)
            {
                foreach (Cookie cookie in cookies)
                {
                    request.CookieContainer.Add(cookie);
                }
            }

            if (requestBody != null)
            {
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(buffer, 0, buffer.Length);
                }
            }

            try
            {
                response = request.GetResponse() as HttpWebResponse;
            }
            catch (WebException ex)
            {
                site.Assert.Fail("A WebException happened when connecting the server, The exception is {0}.", ex.Message);
            }

            return response;
        }