Simple Method to Test Rest Web Service



  private static string CallRestMethod(string url)  
  {  
       var webrequest = (HttpWebRequest)WebRequest.Create(url);  
       webrequest.Method = "GET";  
       webrequest.ContentType = "application/x-www-form-urlencoded";  
       webrequest.Headers.Add("Username", "xyz");  
       webrequest.Headers.Add("Password", "abc");  
       var webresponse = (HttpWebResponse)webrequest.GetResponse();  
       Encoding enc = Encoding.GetEncoding("utf-8");  
       var responseStream = new StreamReader(webresponse.GetResponseStream(), enc);  
       string result = responseStream.ReadToEnd();  
       webresponse.Close();  
       return result;  
  }  

Comments

Popular posts from this blog

Deep dive into OpenXML Part 1

Deep dive into OpenXML Part 2

Convert XML data to dynamic (ExpandoObject) Object