Ejemplo n.º 1
0
 /// <summary>
 ///
 /// Send a post request to the ApiServer WebAPI.
 ///
 /// </summary>
 /// <param name="dto"> The Data Transfer Object (DTO) instance </param>
 /// <returns></returns>
 public async Task PostAsJSON(string apiPath, IDTO dto)
 {
     try
     {
         using (_HttpClient = new HttpClient())
         {
             await _HttpClient.PostAsync(
                 $"{PROTOCOL}://localhost:{PORT}/api/{apiPath}",
                 new StringContent( dto.ToJSON(), Encoding.UTF8, "application/json" )
                 );
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine(ex);
         _HttpClient.Dispose();
     }
 }