title: Bad request 400 when exchanging refresh_token for access_token with box.com
body: <p>I have successfully done this in the past for other services, however with box.com I get an error and I've tried everything I could think off and that others have suggested here.</p>
  
  <p>I'm using .NET C#;</p>
  
  <pre><code>string postdata = "";
  postdata += "client_id=" + HttpUtility.UrlEncode(client_id) + "&amp;";
  postdata += "client_secret=" + HttpUtility.UrlEncode(client_secret) + "&amp;";
  postdata += "refresh_token=" + HttpUtility.UrlEncode(refreshToken) + "&amp;";
  postdata += "redirect_uri=" + HttpUtility.UrlEncode(_redirectUri) + "&amp;";
  postdata += "grant_type=refresh_token";
  
  var json = PostResponse(new Uri(@"https://www.box.com/api/oauth2/token"), postdata);
  </code></pre>
  
  <p>I've tried both with and without urlencoding of the values. Normally urlencoding is not needed in my experience.
  I've also tried different order of parameters.</p>
  
  <pre><code>private string PostResponse(Uri uri, string postdata)
  {
      var bytes = Encoding.UTF8.GetBytes(postdata);
  
      var request = (HttpWebRequest)WebRequest.Create(uri);
      request.Method = WebRequestMethods.Http.Post;
      request.ContentType = "application/x-www-form-urlencoded; charset=utf-8";
      request.ContentLength = bytes.Length;
  
      Stream OutputStream = request.GetRequestStream();
      OutputStream.Write(bytes, 0, bytes.Length);
  
      var response = request.GetResponse();
      var reader = new StreamReader(response.GetResponseStream());
      return reader.ReadToEnd();
  }
  </code></pre>
  
  <p>This code fails with error 400 (bad request). Similar code works fine with for example Google Drive.</p>
  
  <p>Can anyone spot what I'm doing wrong with box.com? Thanks!</p>