title: Getting "Bad Request" error for POST request to salesforce API
body: <p>I am trying to send a POST request to salesforce api in C# but I am getting Bad Request error 400.</p>
  
  <blockquote>
    <p>Error: An unhandled exception of type 'System.Net.WebException'
    occurred in System.dll</p>
  </blockquote>
  
  <p>Additional information: The remote server returned an error: (400) Bad Request.</p>
  
  <pre><code>var request = (HttpWebRequest)WebRequest.Create("https://login.salesforce.com/services/oauth2/token");
  
  var postData = "grant_type=password";
  postData += "&amp;client_id=A73MVG9qBb0Fl2vjGhrbZAN2hk9zfTsODFzWH";
  postData += "&amp;client_secret=35027716280633505312";
  postData += "&amp;username=amir@gmail.com";
  postData += "&amp;password=1234567890Fu0qqKrUodRcpMLuHrviyqX3u";
  
  var data = Encoding.ASCII.GetBytes(postData);
  
  request.Method = "POST";
  request.ContentType = "application/x-www-form-urlencoded";
  request.ContentLength = data.Length;
  
  using (var stream = request.GetRequestStream())
  {
        stream.Write(data, 0, data.Length);
  }
  
  var response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>I sent my POST request with Postman, it works. but generated code with Postman for C# returns the same error.</p>
  
  <pre><code>var client = new RestClient("https://login.salesforce.com/services/oauth2/token");
  var request = new RestRequest(Method.POST);
  request.AddHeader("content-type", "application/x-www-form-urlencoded");
  request.AddHeader("postman-token", "082809c3-f3f4-14f1-81f7-d6832618f905");
  request.AddHeader("cache-control", "no-cache");
  request.AddParameter("application/x-www-form-urlencoded", "grant_type=password&amp;client_id=A73MVG9qBb0Fl2vjGhrbZAN2hk9zfTsODFzWH&amp;client_secret=35027716280633505312&amp;username=amir%40gmail.com&amp;password=1234567890Fu0qqKrUodRcpMLuHrviyqX3u", ParameterType.RequestBody);
  IRestResponse response = client.Execute(request);
  </code></pre>