SHARE
TWEET

Untitled

a guest Apr 18th, 2019 194 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public enum httpVerb
  2.     {
  3.         GET, POST, PUT, DELETE
  4.     }
  5.  
  6.     class RestClient
  7.     {
  8.         public string endPoint { get; set; }
  9.         public httpVerb httpMethod { get; set; }
  10.  
  11.         public RestClient()
  12.         {
  13.             endPoint = string.Empty;
  14.             httpMethod = httpVerb.GET;
  15.         }
  16.  
  17.         public string MakeRequest()
  18.         {
  19.             string strResponseValue = string.Empty;
  20.  
  21.             HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
  22.  
  23.             request.Method = httpMethod.ToString();
  24.  
  25.             using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
  26.             {
  27.                 if (response.StatusCode != HttpStatusCode.OK)
  28.                 {
  29.                     throw new ApplicationException("Error:" + response.StatusCode);
  30.                 }
  31.            
  32.  
  33.                 using (Stream responseStream = response.GetResponseStream())
  34.                 {
  35.                     if (responseStream != null)
  36.                     {
  37.                         using (StreamReader reader = new StreamReader(responseStream))
  38.                         {
  39.                             strResponseValue = reader.ReadToEnd();
  40.                         }//end of stream
  41.                     }
  42.                 }
  43.  
  44.             }
  45.  
  46.             return strResponseValue;
  47.         }
  48.  
  49.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top