WebClient发送Post请求实例

List<BaseModuleEntity> returnResult = new List<BaseModuleEntity>();
            try
            {
                string url = System.Configuration.ConfigurationManager.AppSettings["LogonService"] + "/PermissionService.ashx";
                
                WebClient webClient = new WebClient();
                NameValueCollection postValues = new NameValueCollection();
                postValues.Add("Function", "GetPermissionList");
                postValues.Add("UserInfo", userInfo.Serialize());
                postValues.Add("SystemCode", systemCode);
                postValues.Add("fromCache", false.ToString());
                // 向服务器发送POST数据
                byte[] responseArray = webClient.UploadValues(url, postValues);
                string response = Encoding.UTF8.GetString(responseArray);
                if (!string.IsNullOrEmpty(response))
                {
                    JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
                    returnResult = javaScriptSerializer.Deserialize<List<BaseModuleEntity>>(response);
                    returnResult = returnResult.OrderBy(t => t.SortCode).ToList();
                    HttpContext.Current.Session[permissionKey] = returnResult;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());
            }
            return returnResult;

猜你喜欢

转载自www.cnblogs.com/sharing1986687846/p/10307062.html