Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Net.Http;
- using System.Threading.Tasks;
- namespace OsumaTransfer
- {
- class Program
- {
- static void Main(string[] args)
- {
- string addOrGet = Console.ReadLine();
- string basketid = "";
- string url = "";
- if (addOrGet == "Get")
- {
- Console.WriteLine("---Enter Basket ID---");
- basketid = Console.ReadLine();
- url = $"removed";
- }
- else
- if (addOrGet == "Add")
- {
- url = $"removed";
- }
- HttpClient cons = new HttpClient();
- cons.BaseAddress = new Uri(url);
- cons.DefaultRequestHeaders.Accept.Clear();
- cons.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json"));
- Product product = new Product
- {
- productId = "27795",
- amount = 1,
- customerid = 0,
- returnbasketid = true
- };
- if (addOrGet == "Add")
- {
- CreateProductAsync(cons, product).Wait();
- }
- else
- {
- MyAPIGet(cons, basketid).Wait();
- }
- }
- static async Task MyAPIGet(HttpClient cons, string basketid)
- {
- using (cons)
- {
- HttpResponseMessage res = await cons.GetAsync("");
- res.EnsureSuccessStatusCode();
- if (res.IsSuccessStatusCode)
- {
- Console.WriteLine("\n");
- Console.WriteLine("---------------------Calling Get Operation------------------------");
- Console.WriteLine("\n");
- Console.WriteLine("-----------------------------------------------------------");
- Console.WriteLine(res.Content.ReadAsStringAsync().Result);
- // Console.ReadLine();
- }
- }
- }
- static async Task CreateProductAsync(HttpClient cons, Product product)
- {
- using (cons)
- {
- HttpResponseMessage res = cons.PostAsJsonAsync("", product).Result;
- res.EnsureSuccessStatusCode();
- Console.WriteLine(res.Content.ReadAsStringAsync().Result);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement