Advertisement
Guest User

Untitled

a guest
Sep 24th, 2019
186
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. using System;
  2. using System.Net.Http;
  3. using System.Threading.Tasks;
  4.  
  5. namespace OsumaTransfer
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. string addOrGet = Console.ReadLine();
  12. string basketid = "";
  13. string url = "";
  14. if (addOrGet == "Get")
  15. {
  16. Console.WriteLine("---Enter Basket ID---");
  17. basketid = Console.ReadLine();
  18. url = $"removed";
  19. }
  20. else
  21. if (addOrGet == "Add")
  22. {
  23. url = $"removed";
  24. }
  25.  
  26. HttpClient cons = new HttpClient();
  27. cons.BaseAddress = new Uri(url);
  28. cons.DefaultRequestHeaders.Accept.Clear();
  29. cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
  30.  
  31. Product product = new Product
  32. {
  33. productId = "27795",
  34. amount = 1,
  35. customerid = 0,
  36. returnbasketid = true
  37. };
  38.  
  39. if (addOrGet == "Add")
  40. {
  41. CreateProductAsync(cons, product).Wait();
  42. }
  43. else
  44. {
  45. MyAPIGet(cons, basketid).Wait();
  46. }
  47. }
  48. static async Task MyAPIGet(HttpClient cons, string basketid)
  49. {
  50.  
  51. using (cons)
  52. {
  53. HttpResponseMessage res = await cons.GetAsync("");
  54. res.EnsureSuccessStatusCode();
  55. if (res.IsSuccessStatusCode)
  56. {
  57. Console.WriteLine("\n");
  58. Console.WriteLine("---------------------Calling Get Operation------------------------");
  59. Console.WriteLine("\n");
  60. Console.WriteLine("-----------------------------------------------------------");
  61. Console.WriteLine(res.Content.ReadAsStringAsync().Result);
  62. // Console.ReadLine();
  63. }
  64. }
  65. }
  66.  
  67. static async Task CreateProductAsync(HttpClient cons, Product product)
  68. {
  69. using (cons)
  70. {
  71. HttpResponseMessage res = cons.PostAsJsonAsync("", product).Result;
  72. res.EnsureSuccessStatusCode();
  73. Console.WriteLine(res.Content.ReadAsStringAsync().Result);
  74. }
  75. }
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement