title: C# REST API Call - Working in Postman, NOT in Code
body: <p>I have some existing code that was working and all-of-a-sudden quit.</p>
  
  <p>I can't figure out why...</p>
  
  <p>Here is my code:</p>
  
  <pre><code>public static string RequestToken(string u, string pw)
  {
      string result = string.Empty;
  
      string strUrl = "https://xxx.cloudforce.com/services/oauth2/token?grant_type=password&amp;client_id=XXXX&amp;client_secret=XXXX&amp;username=" + u + "&amp;password=" + pw;
      HttpWebRequest tokenRequest = WebRequest.Create(strUrl) as HttpWebRequest;
      Debug.Print(strUrl);
      tokenRequest.Method = "POST";
      try
      {
          using (HttpWebResponse tokenResponse = tokenRequest.GetResponse() as HttpWebResponse)
          {
              if (tokenResponse.StatusCode != HttpStatusCode.OK)
                  throw new Exception(String.Format(
                      "Server error (HTTP {0}: {1}).",
                      tokenResponse.StatusCode,
                      tokenResponse.StatusDescription));
              DataContractJsonSerializer jsonSerializer2 = new DataContractJsonSerializer(typeof(ResponseAuthentication));
              object objTokenResponse = jsonSerializer2.ReadObject(tokenResponse.GetResponseStream());
              ResponseAuthentication jsonResponseAuthentication = objTokenResponse as ResponseAuthentication;
              result = jsonResponseAuthentication.strAccessToken;
          }
      }
      catch (Exception ex)
      {
          Debug.Print(ex.InnerException.ToString());
      }
      return result;
  }
  </code></pre>
  
  <p>I am now getting a <code>500 Internal Server Error</code> where before this was working cleanly.</p>
  
  <p>When I try to debug using Postman, I pass the URL directly and it works fine. Even when I put a stop in the code and use the exact same URL that then fails from inside the code, it works in Postman, but not in C#.</p>
  
  <p>Out of Postman, I get an orderly...</p>
  
  <pre><code>{
    "access_token": "XXXXXX",
    "instance_url": "https://xxx.cloudforce.com",
    "id": "https://login.salesforce.com/id/XXXXXX",
    "token_type": "Bearer",
    "issued_at": "XXXXXX",
    "signature": "XXXXXX"
  }
  </code></pre>
  
  <p>To clarify, I have tried a <code>GET</code> request instead of <code>POST</code> and I receive the following response (in Postman):</p>
  
  <pre><code>{
    "error": "invalid_request",
    "error_description": "must use HTTP POST"
  }
  </code></pre>
  
  <p>Any ideas here?</p>