Advertisement
Guest User

Untitled

a guest
Oct 21st, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Net;
  6. using System.Net.Http;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9.  
  10. namespace RestClient
  11. {
  12. public enum httpVerb
  13. {
  14. GET,
  15. POST,
  16. PUT,
  17. DELETE,
  18. PATH
  19. }
  20. public class restClient
  21. {
  22. private string responceString;
  23.  
  24. public string Url { get; set; }
  25. public HttpMethod Method { get; set; }
  26.  
  27.  
  28. public restClient()
  29. {
  30. this.Url = "";
  31. this.Method = HttpMethod.Get;
  32. }
  33.  
  34. public string makeRequest()
  35. {
  36.  
  37. string strResponseValue = string.Empty;
  38.  
  39. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
  40.  
  41. request.Method = Method.ToString();
  42.  
  43. using (HttpWebResponse responce = (HttpWebResponse)request.GetResponse())
  44. {
  45. if (responce.StatusCode != HttpStatusCode.OK)
  46. {
  47. responceString = "Error code: " + responce.StatusCode.ToString();
  48. }
  49. else
  50. {
  51. using (Stream responceStream = responce.GetResponseStream())
  52. {
  53. if (responceStream != null)
  54. {
  55. using (StreamReader reader = new StreamReader(responceStream))
  56. {
  57. responceString += reader.ReadToEnd();
  58. }
  59. }
  60. }
  61. }
  62. }
  63. return responceString;
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement