public class RestClient { private HttpWebRequest CreateHttpRequest(string url, string method) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); this.SetProxy(request); request.Headers.Set("Cache-Control", "No-Cache"); request.Method = method; request.ContentType = "application/json"; return request; } public virtual T Post<T>(string url, object requestContact) where T : class { T local; HttpWebRequest request = this.CreateHttpRequest(url, "Post"); if (requestContact != null) { using (Stream stream = request.GetRequestStream()) { new DataContractJsonSerializer(requestContact.GetType()).WriteObject(stream, requestContact); } } using (WebResponse response = request.GetResponse()) { using (Stream stream2 = response.GetResponseStream()) { local = new DataContractJsonSerializer(typeof(T)).ReadObject(stream2) as T; } } return local; } public T Get<T>(string url, object requestContact) where T : class { T local; HttpWebRequest request = this.CreateHttpRequest(url, "GET"); if (requestContact != null) { using (Stream stream = request.GetRequestStream()) { new DataContractJsonSerializer(requestContact.GetType()).WriteObject(stream, requestContact); } } using (WebResponse response = request.GetResponse()) { using (Stream stream2 = response.GetResponseStream()) { local = new DataContractJsonSerializer(typeof(T)).ReadObject(stream2) as T; } } return local; } private void SetProxy(HttpWebRequest request) { WebProxy proxy2 = new WebProxy { Credentials = CredentialCache.DefaultCredentials }; WebProxy proxy = proxy2; request.Proxy = proxy; } }