function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
RoundRound 

400 Bad Request responsed when getting the Access Token

I am trying to authenticate my remote access app, I can successfully get the code in the first step but when I send the second post to https://login.salesforce.com/services/oauth2/token I get a 400 Bad Request. Here is the .net code I am using, anyone have any ideas why this might not be working?
public string PostWebRequest(string postUrl, string paramData, Encoding dataEncode)
        {
            string ret = string.Empty;

            try
            {

                byte[] byteArray = dataEncode.GetBytes(paramData);
                HttpWebRequest webReq = (HttpWebRequest)WebRequest.Create(new Uri(postUrl));
                webReq.Method = "POST";
                webReq.ContentType = "application/x-www-form-urlencoded";

                webReq.ContentLength = byteArray.Length;
                Stream newStream = webReq.GetRequestStream();
                newStream.Write(byteArray, 0, byteArray.Length);//写入参数
                newStream.Close();
                HttpWebResponse response = (HttpWebResponse)webReq.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.Default);
                ret = sr.ReadToEnd();
                sr.Close();
                response.Close();
                newStream.Close();
            }
            catch (WebException e)
            {
                Response.Write(e.Message);
            }
            return ret;
        }
ShashankShashank (Salesforce Developers) 
If this is happening in a sandbox, it could be because of what is stated here: https://github.com/developerforce/Force.com-Toolkit-for-NET/issues/36
Govind BishtGovind Bisht
Same issue here