当前位置:编程学习 > C#/ASP.NET >>

有谁做个模拟登陆没?

https://mid.live.com/si/login.aspx我来是登不上去,不知道那里出错了

 public static string Login(String url, String paramList)
    {
        HttpWebResponse res = null;
        string strResult = "";
        try
        {
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
            req.Method = "POST";
            req.ContentType = "application/x-www-form-urlencoded";
            req.AllowAutoRedirect = false;
            CookieContainer cookieCon = new CookieContainer();
            req.CookieContainer = cookieCon;
            StringBuilder UrlEncoded = new StringBuilder();
            Char[] reserved = { '?', '=', '&' };
            byte[] SomeBytes = null;
            if (paramList != null)
            {
                int i = 0, j;
                while (i < paramList.Length)
                {
                    j = paramList.IndexOfAny(reserved, i);
                    if (j == -1)
                    {
                        UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, paramList.Length - i)));
                        break;
                    }
                    UrlEncoded.Append(HttpUtility.UrlEncode(paramList.Substring(i, j - i)));
                    UrlEncoded.Append(paramList.Substring(j, 1));
                    i = j + 1;
                }
                SomeBytes = Encoding.UTF8.GetBytes(UrlEncoded.ToString());
                req.ContentLength = SomeBytes.Length;
                Stream newStream = req.GetRequestStream();
                newStream.Write(SomeBytes, 0, SomeBytes.Length);
                newStream.Close();
            }
            else
            {
                req.ContentLength = 0;
            }
      
            res = (HttpWebResponse)req.GetResponse();
           string cookieheader = req.CookieContainer.GetCookieHeader(new Uri(url));
            Stream ReceiveStream = res.GetResponseStream();
            Encoding encode = System.Text.Encoding.GetEncoding("GBK");
            StreamReader sr = new StreamReader(ReceiveStream, encode);
            Char[] read = new Char[256];
            int count = sr.Read(read, 0, 256);
            while (count > 0)
            {
                String str = new String(read, 0, count);
                strResult += str;
                count = sr.Read(read, 0, 256);
            }
        }
        catch (Exception e)
        {
            strResult = e.ToString();
        }
        finally
        {
            if (res != null)
            {
                res.Close();
            }
        }
        return strResult;
    }

//调用
postDatas="LoginTextBox=yang123_520@hotmail.com&PasswordTextBox=yangxinqq&__EVENTTARGET=PasswordSubmit&__EVENTARGUMENT=&SavePasswordCheckBox=0&PasswordSubmit=%B5%C7%C2%BD";
        strLogin = Login(uriString, postDatas);
        Page.Response.Write(strLogin);


帮忙调试下,谢谢 --------------------编程问答-------------------- 看看这个
http://topic.csdn.net/u/20090716/23/6fb49f78-cb9f-4bbf-bf9e-472290d1daec.html --------------------编程问答-------------------- 上面发错了,是这个
http://topic.csdn.net/u/20090612/15/717a57c2-66c8-403e-af6c-944f030e389f.html --------------------编程问答-------------------- .. --------------------编程问答-------------------- jf --------------------编程问答--------------------
引用 1 楼 chybin500 的回复:
看看这个
http://topic.csdn.net/u/20090716/23/6fb49f78-cb9f-4bbf-bf9e-472290d1daec.html


没用哦,来点实际的吧 --------------------编程问答-------------------- 新手,不会,学习。
O(∩_∩)O~
要是LZ不介意可以等个1年,我成了经验人士后回来回答你......
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,