title: Call to HttpClient.PostAsync() cancelling task with system.threading.tasks.task.throwifexceptional exception
body: <p>I am trying to create a PDF from the HTML. This part is done in a PHP file with a third party tool. When tested in the development server is working fine. But while moved to <strong>Live</strong> server, the call to <strong>HttpClient.PostAsync</strong> is throwing below error.</p>
  
  <blockquote>
    <p>at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean
    includeTaskCanceledExceptions)    at
    System.Threading.Tasks.Task'1.GetResultCore(Boolean
    waitCompletionNotification)    at
    System.Threading.Tasks.Task'1.get_Result()
    at myProject.mymethod(Int32[] myIds) in path\MyClass.cs:line</p>
  </blockquote>
  
  <p>My Code:</p>
  
  <pre><code>public static void TestFunction()
  {
      try
      {
          string htmlToRender = "My Test Data";
  
          // Convert the string into HttpContent object
          HttpContent stringContent = new StringContent(htmlToRender);
  
          using (var formData = new MultipartFormDataContent())
          {
              formData.Add(stringContent, "htmlToRender");
  
              Task&lt;System.IO.Stream&gt; response = GetHttpContent(formData);
  
              return response.Result;
          }
      }
      catch (HttpRequestException ex)
      {
          Console.WriteLine(ex.Message + "innerExc" + ex.InnerException);
          Console.ReadLine();
      }
  }
  
  private async Task&lt;Stream&gt; GetHttpContent(MultipartFormDataContent ahttpContent)
  {
      using (var client = new HttpClient())
      {
  
          HttpResponseMessage response = await client.PostAsync(
                          "--My request uri to the PHP file--", ahttpContent);
  
          if (!response.IsSuccessStatusCode)
          {
              return null;
          }
          return response.Content.ReadAsStreamAsync().Result;
      }
  }
  </code></pre>
  
  <p>Upgraded my <strong>.Net framework version to 4.5</strong></p>