问题描述
var pvars = new Dictionary<string, string>{ {"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 ... 6quot;); 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<HxTokenModel>(str); reader.Close(); response.Close(); 这样写问题在哪?
解决方案
获取token就是调用我们的rest获取token的接口,你现在获取token是返回什么错误了?