2 a01163125 a01163125 于 2014.04.10 20:08 提问

抓包的时候字典里面没有值。

为什么这个会有错误呢? 谁有类似的demo吗?

private void btnLogin_Click(object sender, EventArgs e)
{
string username = txtUserName.Text;
string password = txtPwd.Text;

        HttpItem itemSign = new HttpItem()
        {
            URL = "https://account.xiaomi.com/pass/serviceLogin",
        };
        HttpHelper helperSign = new HttpHelper();
        HttpResult resultSign = helperSign.GetHtml(itemSign);
        string signHtml = resultSign.Html;
        txtInfo.Text = signHtml;
        HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
        doc.LoadHtml(signHtml);
        var htmlnodes = doc.DocumentNode.Descendants();
        Dictionary<string, string> dict = new Dictionary<string, string>();
        foreach (var item in htmlnodes)
        {
            if (item.Attributes["name"] != null && item.Attributes["value"] != null)
            {
                dict.Add(item.Attributes["name"].Value, item.Attributes["value"].Value);
            }
        }
        string passToken = HttpUtility.UrlEncode(dict["passToken"]);
        string callback = HttpUtility.UrlEncode(dict["callback"]);
        string sid = HttpUtility.UrlEncode(dict["sid"]);
        string qs = HttpUtility.UrlEncode(dict["qs"]);
        string hidden = HttpUtility.UrlEncode(dict["hidden"]);
        string _sign = HttpUtility.UrlEncode(dict["_sign"]);
        string auto = HttpUtility.UrlEncode(dict["auto"]);

        cookies = resultSign.Cookie;

        HttpItem itemLogin = new HttpItem()         //登陆Post
        {
            URL = "https://account.xiaomi.com/pass/serviceLoginAuth2",
            Method = "POST",
            Cookie = cookies,
            Referer = "https://account.xiaomi.com/pass/serviceLogin",
            ContentType = "application/x-www-form-urlencoded",
            Postdata = string.Format("passToken={0}&user={1}&pwd={2}&callback={3}&sid={4}&qs={5}&hidden={6}&_sign={7}&auto={8}", passToken, username, password, callback, sid, qs, hidden, _sign, auto)
        };
        HttpHelper helperLogin = new HttpHelper();
        HttpResult resultLogin = helperLogin.GetHtml(itemLogin);

        if (resultLogin.Html.Contains("小米帐户 - 登录"))
        {
            AppendText(username + "登陆失败\n"); return;
        }
        AppendText(username + "登陆成功");
        cookies += ";" + resultLogin.Cookie;
        // AppendText(cookies);

    }
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!