Пример #1
0
        /// <summary>
        /// Отправка запроса на сервер
        /// </summary>
        /// <param name="service">Сервисный адрес</param>
        /// <param name="requestType">Тип объекта класса</param>
        /// <returns></returns>
        private object ResultPost(string service, object requestType)
        {
            string resultServer;
            var    json    = new SerializeJson();
            var    js      = json.JsonLibraryNullInclude(requestType);
            var    body    = Encoding.UTF8.GetBytes(js);
            var    request = (HttpWebRequest)WebRequest.Create(service);

            request.Method        = "POST";
            request.ContentType   = "application/json";
            request.ContentLength = body.Length;
            using (Stream stream = request.GetRequestStream())
            {
                stream.Write(body, 0, body.Length);
                stream.Close();
            }
            WebResponse response = request.GetResponse();

            using (StreamReader rdr = new StreamReader(response.GetResponseStream()))
            {
                resultServer = rdr.ReadToEnd();
            }
            response.Close();
            response.Dispose();
            return(json.JsonDeserializeObjectClass <ModelPathReport>(resultServer));
        }