Любая помощь здесь оценивается. Я просто пытаюсь выполнить основной вызов Oauth Username-Password Flow. Это дает мне неправильный запрос (400) Ошибка при попытке вызвать GetResponse().API Salesforce Rest OAuth - ошибка плохой реакции
string sessionId = String.Empty;
string url = ConfigurationManager.AppSettings["SfdcLoginUrl"].ToString();
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://test.salesforce.com/services/oauth2/token");
request.Method = "POST";
request.ContentType = "application/json";
StringBuilder sb = new StringBuilder();
sb.Append("grant_type=password&");
sb.Append("client_id=" + ConfigurationManager.AppSettings["ClientId"].ToString() + "&");
sb.Append("client_secret=" + ConfigurationManager.AppSettings["ClientSecret"].ToString() + "&");
sb.Append("username=" + HttpUtility.UrlPathEncode(username) + "&");
sb.Append("password=" + HttpUtility.UrlPathEncode(password));
System.Text.ASCIIEncoding encoding = new ASCIIEncoding();
byte[] bytes = encoding.GetBytes(sb.ToString());
request.ContentLength = bytes.Length;
using (Stream requestStream = request.GetRequestStream())
{
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
}
WebResponse response = request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
sessionId = reader.ReadToEnd();
вы послали ContentType быть JSON, но вы не посылаете JSON. – superfell
Appologies, я должен был указать. Изменение типа содержимого на «application/x-www-form-urlencoded» также дает ту же ошибку. Это было просто улаживание в моей (несколько слепой, на данный момент) возиться – Suburbanpsyco6
вы aren; t кодирование clientId или секрет. также, когда вы получите 400 взглядов на тело ответа, у которого будет больше информации – superfell