title: Making HTTP Post with authorization in C#
body: <p>I'm trying to <a href="https://developer.paypal.com/webapps/developer/docs/integration/direct/make-your-first-call/" rel="nofollow">Make your first call Paypal</a> where the post message are in curl. I want to convert them to C#. But I can't edit <code>Accept</code> header.</p>
  
  <pre><code>curl https://api.sandbox.paypal.com/v1/oauth2/token \
   -H "Accept: application/json" \
   -H "Accept-Language: en_US" \
   -u "EOJ2S-Z6OoN_le_KS1d75wsZ6y0SFdVsY9183IvxFyZp:EClusMEUk8e9ihI7ZdVLF5cZ6y0SFdVsY9183IvxFyZp" \
   -d "grant_type=client_credentials"
  </code></pre>
  
  <p>My code is </p>
  
  <pre><code>string url = "https://api.sandbox.paypal.com/v1/oauth2/token";
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);            
  
  //request.ContentType = "Content-type: text/xml";
  //Client.Headers.Add(HttpRequestHeader.UserAgent, "user agent to send");
  //request.Headers.Add(HttpRequestHeader.Accept, "application/json");
  //request.Headers.Add(HttpRequestHeader.Referer, "string");
  //request.Headers.Add(HttpRequestHeader.AcceptLanguage, "string");
  
  request.Method = "POST";
  string authInfo = "AfKNLhCngYfGb-Eyv5gn0MnzCDBHD7T9OD7PATaJWQzP3I1xDRV1mMK1i3WO:ECSAgxAiBE00pq-SY9YB5tHw0fd2UlayHGfMr5fjAaULMD2NFP1syLY7GCzt";
  request.Headers["Authorization"] = "Basic " + Convert.ToBase64String(Encoding.ASCII.GetBytes(authInfo));
  //request.Headers["Accept"] = "application/json";
  request.Headers["Accept-Language"] = "en_US";
  byte[] buffer = Encoding.GetEncoding("UTF-8").GetBytes("grant_type=client_credentials");
  Stream reqstr = request.GetRequestStream();
  reqstr.Write(buffer, 0, buffer.Length);
  reqstr.Close();
  
  HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  </code></pre>
  
  <p>I'm getting internal server error 500. But it works fine with curl. How can I do this in C#?</p>