WebClient发送Post请求实例

WebClient发送Post请求实例

 

 

List returnResult = new List();
            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>(response);
                    returnResult = returnResult.OrderBy(t => t.SortCode).ToList();
                    HttpContext.Current.Session[permissionKey] = returnResult;
                }
            }
            catch (Exception ex)
            {
                Log.Write(ex.ToString());
            }
            return returnResult;

 

posted @ 2019-01-23 08:48 波霸38 阅读( ...) 评论( ...) 编辑 收藏

你可能感兴趣的:(WebClient发送Post请求实例)