title: HttpClient post with parameters in body
body: <p>I am successful using Postman doing a post for authentication. However, I can't seem to get it to work from C# and am getting a 401 error. The password and username are verified the same as in Postman.  How can I do it?</p>
  <p>Here is my code:</p>
  <pre class="lang-cs prettyprint-override"><code>var url = AppConstants.ApiLoginUrl;
  var uriRequest = new Uri(url);
  string httpResponseBody;
  
  using (var httpClient = new Windows.Web.Http.HttpClient())
  {
      var content = new HttpStringContent(string.Format(&quot;username={0}&amp;password={1}&quot;, email, password), Windows.Storage.Streams.UnicodeEncoding.Utf8, &quot;application/x-www-form-urlencoded&quot;);
  
      try
      {
          var httpResponse = await httpClient.PostAsync(uriRequest, content);
          ...
      }
  }
  </code></pre>
  <p>Here are the settings in Postman for header and body.</p>
  <p><a href="https://i.stack.imgur.com/xD2js.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xD2js.png" alt="Enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/FUMLI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/FUMLI.png" alt="Enter image description here" /></a></p>
  <p>Now using this code for the content parameter:</p>
  <pre class="lang-cs prettyprint-override"><code>var content = new HttpFormUrlEncodedContent(new[]
  {
      new KeyValuePair&lt;string, string&gt;(&quot;username&quot;, email),
      new KeyValuePair&lt;string, string&gt;(&quot;password&quot;, password)
  });
  </code></pre>
  <p>Upon a closer look, it appears the username is encoded in Fiddler for both the Postman and code requests. So, my theory about using an encoded username is not quite right.  Here at the snapshots of the requests from Fiddler... Is is possible?</p>
  <p>Postman headers:</p>
  <p><a href="https://i.stack.imgur.com/nodty.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/nodty.png" alt="Postman headers" /></a></p>
  <p>Code headers:</p>
  <p><a href="https://i.stack.imgur.com/sy07Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/sy07Y.png" alt="Code headers" /></a></p>
  <p>Raw View Postman * showing encoded username field:</p>
  <p><a href="https://i.stack.imgur.com/7vEhT.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/7vEhT.png" alt="Raw view revised" /></a></p>
  <p>Raw view code:</p>
  <p><a href="https://i.stack.imgur.com/SBuQq.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SBuQq.png" alt="Raw code" /></a></p>