Пример #1
0
        public void Update(T item)
        {
            HttpWebRequest httpReuest = GetRequest(METHOD_PUT);

            string stringData = RestSerializer.Serialize(item);

            byte[] data = _encoding.GetBytes(stringData);
            httpReuest.ContentLength = data.Length;

            Stream newStream = httpReuest.GetRequestStream();

            newStream.Write(data, 0, data.Length);
            newStream.Close();
            var httpResponse = (HttpWebResponse)httpReuest.GetResponse();
        }
Пример #2
0
        public T Create(T item)
        {
            HttpWebRequest httpReuest = GetRequest(METHOD_POST);
            var            stringData = typeof(T) == typeof(KeyWord) ? RestSerializer.KeyWordCreate(item as KeyWord) : RestSerializer.Serialize(item);

            byte[] data = _encoding.GetBytes(stringData);
            httpReuest.ContentLength = data.Length;

            Stream newStream = httpReuest.GetRequestStream();

            newStream.Write(data, 0, data.Length);
            newStream.Close();
            var    httpResponse = (HttpWebResponse)httpReuest.GetResponse();
            string answer       = "";

            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                answer = streamReader.ReadToEnd();
            }
            return(RestSerializer.Deserialize <T>(answer));
        }