注册

c# 如何获取token,最好有demo

 
  var pvars = new Dictionary
{
    {"grant_type", "client_credentials"},
    {"client_id", MTConfig.ClientId},
    {"client_secret", MTConfig.ClientSecret},
};
         

            HxTokenModel model = new HxTokenModel();
            WebRequest request = HttpWebRequest.Create("https://a1.easemob.com/easemob-demo/chatdemoui/token");

          
            JavaScriptSerializer serializer = new JavaScriptSerializer();
            byte[] buf = System.Text.Encoding.GetEncoding("utf-8").GetBytes(serializer.Serialize(pvars));
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = buf.Length;
      

            request.Method = "POST";
            Stream RequestStream = request.GetRequestStream();
            RequestStream.Close();

             WebResponse response = request.GetResponse();
            StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8"));

            string str = reader.ReadToEnd();
            JavaScriptSerializer serializers = new JavaScriptSerializer();
            model = serializers.Deserialize(str);

            reader.Close();
            response.Close();
 
这样写问题在哪?
 
已邀请:
获取token就是调用我们的rest获取token的接口,你现在获取token是返回什么错误了?

要回复问题请先登录注册