title: HttpClient.SendAsync: 500 - Internal Server Error in Windows Service Application
body: <p>I am seeing the following message in attempting to post a json string to a web API (this is what is written to file in the line containing System.IO.File.WriteAllText):</p>
  
  <pre><code>Response: StatusCode: 500, ReasonPhrase: 'Internal Server Error', Version: 1.1, Content: System.Net.Http.StreamContent, Headers:
  {
    Pragma: no-cache
    Cache-Control: no-cache
    Date: Thu, 13 Aug 2015 21:26:12 GMT
    Server: Microsoft-IIS/8.5
    X-AspNet-Version: 4.0.30319
    X-Powered-By: ASP.NET
    Content-Length: 36
    Content-Type: application/json; charset=utf-8
    Expires: -1
  }
  </code></pre>
  
  <p>The code within my async posting method is as follows:</p>
  
  <pre><code>  Uri theUri = new Uri("http://www.website.com/WebsiteAPI/PostDetails");
  
    HttpClient aClient = new HttpClient();
    aClient.BaseAddress = theUri;
    aClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
    aClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",
        Convert.ToBase64String(
        System.Text.ASCIIEncoding.ASCII.GetBytes(
        string.Format("{0}:{1}", "USERNAME", "PASSWORD"))));
    aClient.DefaultRequestHeaders.Host = theUri.Host;
  
    HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, theUri);
    request.Content = new StringContent(resource, Encoding.UTF8, "application/json");
  
    // Post the data 
    aClient.SendAsync(request).ContinueWith(responseTask =&gt;
        {
            System.IO.File.WriteAllText(PROFILE_JSON_PATH, "Response: " + responseTask.Result);
        });
  </code></pre>
  
  <p>I've tried many different solutions online but nothing seems to work.  Any idea why this may not be working?</p>