Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public enum httpVerb
- {
- GET, POST, PUT, DELETE
- }
- class RestClient
- {
- public string endPoint { get; set; }
- public httpVerb httpMethod { get; set; }
- public RestClient()
- {
- endPoint = string.Empty;
- httpMethod = httpVerb.GET;
- }
- public string MakeRequest()
- {
- string strResponseValue = string.Empty;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(endPoint);
- request.Method = httpMethod.ToString();
- using (HttpWebResponse response = (HttpWebResponse)request.GetResponse())
- {
- if (response.StatusCode != HttpStatusCode.OK)
- {
- throw new ApplicationException("Error:" + response.StatusCode);
- }
- using (Stream responseStream = response.GetResponseStream())
- {
- if (responseStream != null)
- {
- using (StreamReader reader = new StreamReader(responseStream))
- {
- strResponseValue = reader.ReadToEnd();
- }//end of stream
- }
- }
- }
- return strResponseValue;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement