private static HttpWebRequest CreateRequest(string uri, Cookie[] cookies, string contentType, string parameters) { var request = (HttpWebRequest)WebRequest.Create(uri); request.CookieContainer = new CookieContainer(); if (cookies != null) cookies.ToList().ForEach(cookie => request.CookieContainer.Add(cookie)); request.AllowAutoRedirect = false; request.Method = "POST"; request.ContentType = contentType; request.ContentLength = parameters.Length; return request; }