Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Net.Http.Formatting;
- using System.Net.Http;
- using WebAPI_1.Models;
- using System.IO;
- using System.Net.Mail;
- using System.Web.Script.Serialization;
- namespace ConsoleApp1
- {
- class Program
- {
- public static HttpClient client = new HttpClient();
- static void Main(string[] args)
- {
- client.BaseAddress = new Uri("http://localhost:57652/api/");
- client.DefaultRequestHeaders.Add("Accept", "application/json");
- Product produkt = new Product()
- {
- Id = "2",
- Name = "sds"
- };
- PostProducts(produkt);
- GetProducts();
- Console.ReadLine();
- }
- public static async void GetProducts()
- {
- var result = await client.GetAsync("Products");
- var strResult = await result.Content.ReadAsAsync<List<Product>>();
- //var strResult = await result.Content.ReadAsStringAsync();
- Console.WriteLine(strResult);
- }
- public static async void PostProducts(Product product)
- {
- var obj = new Product() { Name = product.Name, Id = product.Id };
- await client.PostAsJsonAsync("Products", obj);
- //await client.PostAsJsonAsync(client.BaseAddress, json);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement