C# Login方法

 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;
            }
        }

 

posted @ 2014-08-29 07:16  韩梦芫  阅读(1250)  评论(0编辑  收藏  举报