title: How to wrap the body of a POST request in order to be able to send restricted characters
body: <p>Using powershell to get the current token of a user from an external service I do not have problem:</p>
  
  <pre><code>$uri = &amp;quot;http://myserver/fmetoken/view&amp;quot;
  $postParams = @{user='Myuser';password='PS78U-w&amp;';}
  $foo = Invoke-WebRequest -Uri $uri -Method Post -Body $postParams
  
  $foo.Content
  </code></pre>
  
  <p>i receive the token.</p>
  
  <p>if I use postman to verify it, there is no issue.</p>
  
  <p>but if I want to implement the same action in c# the response is:
  'The remote server returned an error: (401) Unauthorized.' when the password contains charactesrs like '&amp;' and '='</p>
  
  <pre><code>var url = $"{fmeServerUrl}/fmetoken/view";
  var body = $"user={settingsUserFme}&amp;password={settingsPasswordFme}";
  
  var byteArray = Encoding.UTF8.GetBytes(body);
  var responseCode = 0;
  var request = (HttpWebRequest)WebRequest.Create(url);
  request.Method = "POST";
  request.Credentials = CredentialCache.DefaultCredentials;
  request.ContentType = "application/x-www-form-urlencoded";
  
  request.ContentLength = byteArray.Length;
  var dataStream = request.GetRequestStream();
  dataStream.Write(byteArray, 0, byteArray.Length);
  dataStream.Close();
  
  WebResponse response = request.GetResponse();
  using (var reader = new StreamReader(response.GetResponseStream()))
  {
      responseresult = reader.ReadToEnd();
      reader.Close();
  }
  </code></pre>
  
  <p>I already tried to use:</p>
  
  <pre><code>var bodyencoded = System.Net.WebUtility.UrlEncode(body);
  var byteArray = Encoding.UTF8.GetBytes(bodyencoded);
  </code></pre>
  
  <p>but in this case I receive a bad request</p>