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;

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM