public ApiCreateResponse CreateProduct(ref JsonProduct product) { var json = JsonSerializer.Serialize(product); var data = new StringContent(json, Encoding.UTF8); Console.WriteLine("PRODUCT CREATION " + data.ReadAsStringAsync().Result); var response = client.PostAsync(BASE_URL + "addproduct", data).Result; ApiCreateResponse createResponse = JsonSerializer.Deserialize <ApiCreateResponse>(response.Content.ReadAsStringAsync().Result); createResponse.statusCode = response.StatusCode.GetHashCode(); return(createResponse); }
static void Main(string[] args) { Console.OutputEncoding = Encoding.UTF8; JsonProduct json = new JsonProduct(); string temp = JsonConvert.SerializeObject(json); Console.WriteLine(temp); ApiRequest api = new ApiRequest(); ApiCreateResponse createResponse = api.CreateProduct(ref json); if (createResponse.statusCode == 200) { Console.WriteLine("Creation complete"); } Console.WriteLine(createResponse.id); }