title: HttpClient PostAsync() not working
body: <p>In my Xamarin Forms App</p>
  
  <p>I'm trying to Post a Json String to my webservice wich is RestFul API
  when i use the following code:</p>
  
  <pre><code>public static async Task&lt;bool&gt; SaveRolAsync(Methods Method, Role Rol)
      {
          try
          {
              HttpClient client = new HttpClient();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              var uri = ("http://myservice.com/roles/");
              HttpResponseMessage response = null;
  
              try
              {
                  var jSettings = new JsonSerializerSettings();
                  jSettings.NullValueHandling = NullValueHandling.Ignore;
                  jSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
  
                  var JsonData = JsonConvert.SerializeObject(Rol);
                  var RoleContent = new StringContent(JsonData, Encoding.UTF8, "application/json");
  
                  if (Method == Methods.PUT || Method == Methods.PATCH)
                  {
                      response = await client.PutAsync(uri, RoleContent);
                  }
  
                  if (Method == Methods.POST)
                  {
                      response = await client.PostAsync(uri, RoleContent);
                  }
  
                  if (Method == Methods.DELETE)
                  {
                      throw new NotImplementedException();
                  }
  
                  return response.IsSuccessStatusCode;
  
              }
              catch (JsonException jse)
              {
                  return false;
              }
          }
          catch (Exception ex)
          {
              // Exceptions Throws here
              // @T This line i got The request requires buffering data to succeed
              return false;
          }
      }
  </code></pre>
  
  <p>The Exception throws:</p>
  
  <blockquote>
    <p>The request requires buffering data to succeed</p>
  </blockquote>
  
  <p>Stack Trace:</p>
  
  <blockquote>
    <p>{System.Net.WebException: The request requires buffering data to
    succeed.   at System.Net.HttpWebRequest.EndGetResponse
    (System.IAsyncResult asyncResult) [0x00064] in
    :0    at
    System.Threading.Tasks.TaskFactory<code>1[TResult].FromAsyncCoreLogic
    (System.IAsyncResult iar, System.Func</code>2[T,TResult] endFunction,
    System.Action<code>1[T] endAction, System.Threading.Tasks.Task</code>1[TResult]
    promise, System.Boolean requiresSynchronization) [0x00014] in
    :0 
    --- End of stack trace from previous location where exception was thrown ---   at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
    [0x0000c] in :0    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
    (System.Threading.Tasks.Task task) [0x0004e] in
    :0    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
    (System.Threading.Tasks.Task task) [0x0002e] in
    :0    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd
    (System.Threading.Tasks.Task task) [0x0000b] in
    :0    at
    System.Runtime.CompilerServices.ConfiguredTaskAwaitable<code>1+ConfiguredTaskAwaiter[TResult].GetResult
    () [0x00000] in &lt;a66f207c1e5949e9a252c01e27bbd34e&gt;:0    at
    System.Net.Http.HttpClientHandler+&lt;SendAsync&gt;c__async0.MoveNext ()
    [0x0041e] in &lt;566d6cf6576345098cb5e08ad43d5e78&gt;:0 
    --- End of stack trace from previous location where exception was thrown ---   at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
    [0x0000c] in &lt;a66f207c1e5949e9a252c01e27bbd34e&gt;:0    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
    (System.Threading.Tasks.Task task) [0x0004e] in
    &lt;a66f207c1e5949e9a252c01e27bbd34e&gt;:0    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
    (System.Threading.Tasks.Task task) [0x0002e] in
    &lt;a66f207c1e5949e9a252c01e27bbd34e&gt;:0    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd
    (System.Threading.Tasks.Task task) [0x0000b] in
    &lt;a66f207c1e5949e9a252c01e27bbd34e&gt;:0    at
    System.Runtime.CompilerServices.ConfiguredTaskAwaitable</code>1+ConfiguredTaskAwaiter[TResult].GetResult
    () [0x00000] in :0    at
    System.Net.Http.HttpClient+c__async0.MoveNext ()
    [0x000f3] in &lt;566d6cf6576345098cb5e08ad43d5e78>:0 
    --- End of stack trace from previous location where exception was thrown ---   at
    System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw ()
    [0x0000c] in :0    at
    System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess
    (System.Threading.Tasks.Task task) [0x0004e] in
    :0    at
    System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification
    (System.Threading.Tasks.Task task) [0x0002e] in
    :0    at
    System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd
    (System.Threading.Tasks.Task task) [0x0000b] in
    :0    at
    System.Runtime.CompilerServices.TaskAwaiter`1[TResult].GetResult ()
    [0x00000] in :0    at
    MyAPP.Webservice+d__4.MoveNext () [0x000d0] in
    C:\MyProject\Classes\Webservice.cs:140 }</p>
  </blockquote>
  
  <p>**Also Tried: SendAsync() Ty M. Wiśnicki **</p>
  
  <pre><code>public static async Task&lt;bool&gt; SaveRolAsync(MediwareLib.Methods Method, Role Rol)
      {
          try
          {
              HttpClient client = new HttpClient();
              client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  
              var uri = (BaseRequestUrl + "roles/");
              HttpResponseMessage response = null;
              var request = new HttpRequestMessage();
  
              try
              {
                  var jSettings = new JsonSerializerSettings();
                  jSettings.NullValueHandling = NullValueHandling.Ignore;
                  jSettings.MissingMemberHandling = MissingMemberHandling.Ignore;
  
                  var JsonData = JsonConvert.SerializeObject(Rol);
  
                  var RoleContent = new StringContent(JsonData, Encoding.UTF8, "application/json");
  
                  if (Method == MediwareLib.Methods.PUT || Method == MediwareLib.Methods.PATCH)
                  {
                      request = new HttpRequestMessage(HttpMethod.Put, uri);
                      request.Content = RoleContent;
  
                      response = await client.SendAsync(request,
                      HttpCompletionOption.ResponseHeadersRead);
                  }
  
                  if (Method == MediwareLib.Methods.POST)
                  {
                      request = new HttpRequestMessage(HttpMethod.Post, uri);
                      request.Content = RoleContent;
  
                      response = await client.SendAsync(request,
                      HttpCompletionOption.ResponseHeadersRead);
                  }
  
                  if (Method == MediwareLib.Methods.DELETE)
                  {
                      throw new NotImplementedException();
                      // response = await client.DeleteAsync(uri + Rol.Id);
                  }
  
                  return response.IsSuccessStatusCode;
  
              }
              catch (JsonException jse)
              {
                  Globals.Log("SaveRolAsync: " + jse.ToString());
                  return false;
              }
          }
          catch (Exception ex)
          {
              Globals.Log("SaveRolAsync: " + ex.ToString());
              return false;
          }
  
      }
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/czIaR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/czIaR.png" alt="enter image description here"></a></p>