Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Linq;
- using System.Net;
- using System.Net.Http;
- using System.Text;
- using System.Threading.Tasks;
- namespace RestClient
- {
- public enum httpVerb
- {
- GET,
- POST,
- PUT,
- DELETE,
- PATH
- }
- public class restClient
- {
- private string responceString;
- public string Url { get; set; }
- public HttpMethod Method { get; set; }
- public restClient()
- {
- this.Url = "";
- this.Method = HttpMethod.Get;
- }
- public string makeRequest()
- {
- string strResponseValue = string.Empty;
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
- request.Method = Method.ToString();
- using (HttpWebResponse responce = (HttpWebResponse)request.GetResponse())
- {
- if (responce.StatusCode != HttpStatusCode.OK)
- {
- responceString = "Error code: " + responce.StatusCode.ToString();
- }
- else
- {
- using (Stream responceStream = responce.GetResponseStream())
- {
- if (responceStream != null)
- {
- using (StreamReader reader = new StreamReader(responceStream))
- {
- responceString += reader.ReadToEnd();
- }
- }
- }
- }
- }
- return responceString;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement