我需要知道如何从 Orange Message Api 获取访问令牌。我写了一个应该这样做的函数,但它似乎包含一个错误。它返回一个异常[远程服务器返回一个 errro 400 错误请求]。我不知道出了什么问题
class MessageApi
{
public void GetAccessToken()
{
string AuthHeader = "My Authorization header";
HttpWebRequest requeust = (HttpWebRequest)WebRequest.Create("https://api.orange.com/oauth/v2/token");
requeust.ContentType = "application/json";
requeust.Method = "POST";
JsonObject JsonData = new JsonObject();
JsonData["authorization"] = AuthHeader;
JsonData["grant_type"] = "client_credentials";
using (var streamWriter = new StreamWriter(requeust.GetRequestStream()))
{
streamWriter.Write(JsonData);
}
var httpResponse = (HttpWebResponse)requeust.GetResponse();
using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
{
var result = streamReader.ReadToEnd();
}
}
}