title: C# unsupported grant type when calling web api
body: <p>I am trying to perform a Post to my WebAPI from a c# WPF desktop app.</p>
  
  <p>No matter what I do, I get </p>
  
  <blockquote>
    <p>{"error":"unsupported_grant_type"}</p>
  </blockquote>
  
  <p>This is what I've tried (and I've tried everything I could find):</p>
  
  <p>Also dev web api currently active for testing: <a href="http://studiodev.biz/" rel="noreferrer">http://studiodev.biz/</a></p>
  
  <p>base http client object:</p>
  
  <pre><code>var client = new HttpClient()
  client.BaseAddress = new Uri("http://studiodev.biz/");
  client.DefaultRequestHeaders.Accept.Clear();
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain"));
  client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("*/*"));
  </code></pre>
  
  <p>with the following send methods:</p>
  
  <pre><code>var response = await client.PostAsJsonAsync("token", "{'grant_type'='password'&amp;'username'='username'&amp;'password'='password'");
  var response = await client.PostAsJsonAsync("token", "grant_type=password&amp;username=username&amp;password=password");
  </code></pre>
  
  <p>After that failed, I did some googling and tried:</p>
  
  <pre><code>LoginModel data = new LoginModel(username, password);
  string json = JsonConvert.SerializeObject(data);
  await client.PostAsync("token", new JsonContent(json));
  </code></pre>
  
  <p>same result, so I tried:</p>
  
  <pre><code>req.Content = new StringContent(json, Encoding.UTF8, "application/x-www-form-urlencoded");
  await client.SendAsync(req).ContinueWith(respTask =&gt;
  {
   Application.Current.Dispatcher.Invoke(new Action(() =&gt; { label.Content = respTask.Result.ToString(); }));
  });
  </code></pre>
  
  <p>Note: I can make a successful call with Chrome.</p>
  
  <p><strong>Update Fiddler Result</strong></p>
  
  <p><img src="https://i.stack.imgur.com/qZ9oV.jpg" alt="enter image description here"></p>
  
  <p>Could someone please help me make a successful call to the above web api...
  Please let me know if I can help clarify.
  Thanks!!</p>