发送请求读取接口

来源:互联网 发布:网络打鱼游戏作弊教程 编辑:程序博客网 时间:2024/06/03 16:38
private static Dictionary<int, int> GetCRMUserTypeNew(string phoneNo, string imeiNo)        {            Dictionary<int, int> diction = new Dictionary<int, int>();            try            {                // 发送请求                string url = ConfigurationManager.AppSettings["CRMVipSrvUrl"] + "GetVipUserInfo";                string data = string.Format(@"{{""name"":""getvip"",""pwd"":""getvip@0701"",""phone"":""{0}"",""imei"":""{1}""}}"                    , phoneNo == null ? "" : phoneNo.TrimStart('0'), imeiNo == null ? "" : imeiNo);                byte[] requestBuffer = Encoding.GetEncoding("utf-8").GetBytes(data);                WebRequest request = WebRequest.Create(url);                request.Method = "POST";                request.ContentType = "application/x-www-form-urlencoded";                request.ContentLength = requestBuffer.Length;                using (Stream requestStream = request.GetRequestStream())                {                    requestStream.Write(requestBuffer, 0, requestBuffer.Length);                    requestStream.Close();                }                WebResponse response = request.GetResponse();                using (StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.GetEncoding("utf-8")))                {                    string str = reader.ReadToEnd();                    reader.Close();                    JavaScriptArray billArray = (JavaScriptArray)JavaScriptConvert.DeserializeObject(str);                    if (billArray != null)                    {                        for (int i = 0; i < billArray.Count; i++)                        {                            JavaScriptObject bill = (billArray[i]) as JavaScriptObject;                            JavaScriptArray vipArray = bill["vip"] as JavaScriptArray;                            if (vipArray != null)                            {                                for (int j = 0; j < vipArray.Count; j++)                                {                                    JavaScriptObject vip = (vipArray[j]) as JavaScriptObject;                                    int userTypeId = GetUserTypeId(vip["type"].ToString());                                    int vipLevel = SqlUtils.DBToInt(vip["level"]);                                    if(!diction.ContainsKey(userTypeId))                                    {                                        diction.Add(userTypeId, vipLevel);                                    }                                }                            }                        }                    }                }            }            catch (Exception ex)            {            }            return diction;        }

0 0
原创粉丝点击