Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.82 KB | None | 0 0
  1. public static T callWSGet<T>(string url, string method, bool isAuth)
  2.         {
  3.             T objResponse;
  4.             var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://wssommapositiva/" + url);
  5.             httpWebRequest.ContentType = "text/json";
  6.             httpWebRequest.Method = method;
  7.             // Necessario per token
  8.             if (isAuth)
  9.                 httpWebRequest.Headers.Add("X-Token", HttpContext.Current.Session["Token"].ToString());
  10.  
  11.                 var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
  12.                 using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
  13.                 {
  14.                     objResponse = JsonConvert.DeserializeObject<T>(streamReader.ReadToEnd());
  15.                 }
  16.  
  17.             return objResponse;
  18.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement