title: ASP.NET Api Client
body: <p>I'm learning how to create WEB-API client</p>
  
  <p>I've created some simple API:</p>
  
  <pre><code>[HttpGet]
          public IHttpActionResult GetInfo()
          {
              return Ok("Its working!");
          }
          [HttpPost]
          public IHttpActionResult PostInfo(ClientDataDto dto)
          {
  
              try
              {
                  someMethod(dto.IdKlienta, dto.Haslo, dto.IdZgloszenia, dto.HardwareInfo, dto.SoftwareInfo);
  
                  return Ok("sent");
              }
              catch
              {
                  return BadRequest();
              }
          }
  </code></pre>
  
  <p>For now I just trying to call GET method.
  When I use Fiddler with addr
  localhost:someport/api/Client2 
  its working</p>
  
  <p>but when i try to do it by client, which code is below:</p>
  
  <pre><code>private static HttpClient client = new HttpClient();
  
          static void Main(string[] args)
          {
              #region TESTONLY
              var debug = new XMLData();
              string HardwareInfoXML = debug.HardwareXML;
              string SoftInfoXML = debug.SoftwareXML;
              int id_zgloszenia = 20;
              int idKlienta = 25;
              //haslo = "202cb962ac59075b964b07152d234b70";
              #endregion
  
              var data = new ClientDataDto() { HardwareInfo = HardwareInfoXML, SoftwareInfo = SoftInfoXML, IdKlienta = idKlienta, IdZgloszenia = id_zgloszenia };
              RunAsync(data);
  
          }
  
  
  
  
  
          private static async Task RunAsync(ClientDataDto data)
          {
              var stringContent = new StringContent(JsonConvert.SerializeObject(data), Encoding.UTF8, "application/json");
  
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
              client.BaseAddress = new Uri(@"http://localhost:7774/api/client2/");
              var url = new Uri(@"http://localhost:7774/api/client2/");
  
              var res1 = await client.GetAsync(url);
              var res = await client.PostAsync(url, stringContent);
              res.EnsureSuccessStatusCode();
  
          }
  </code></pre>
  
  <p>Application closing without any info at </p>
  
  <pre><code>var res1 = await client.GetAsync(url);
  </code></pre>
  
  <p>I have checked to see all exceptions in Debug exception Windows, but it is just closing after trying call GetAsync
  PostASync doesn't work too.</p>
  
  <p>What is wrong here?</p>