码迷,mamicode.com
首页 > 其他好文 > 详细

C# Login方法

时间:2014-08-29 08:19:27      阅读:288      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   os   io   ar   for   div   

 public static bool User_Login(string url, string uname, string password, out string[] userInfo)
        {
            string param = "username=" + uname + "&password=" + password;
            byte[] bs = Encoding.UTF8.GetBytes(param);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.ContentLength = bs.Length;

            Stream httpStream = request.GetRequestStream();
            httpStream.Write(bs, 0, bs.Length);
            httpStream.Close();
            try
            {
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader sr = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
                string result_Msg = sr.ReadToEnd();
                response.Close();
                sr.Close();
                return AnalysisResponseMsg(result_Msg, out userInfo);
            }
            catch (Exception ex)
            {
                string[] msg = { 
                                   "RESULT", ex.Message 
                               };
                userInfo = msg;
                return false;
            }
        }

 

C# Login方法

标签:style   blog   http   color   os   io   ar   for   div   

原文地址:http://www.cnblogs.com/siyunianhua/p/3944053.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!