-2

我正在尝试使用 WebClient 验证 Google 帐户。

class PostDataBuilder 
{
    private static Dictionary<string, string> 
        ToPropertyDictionary(object data) 
    { 
        var values = data
            .GetType()
            .GetProperties()
            .Select(x => new { 
                                Key = x.Name, 
                                Value = x.GetValue(data, null) 
                             });

        var result = new Dictionary<string, string>();
        foreach (var item in values)
            result.Add(item.Key, item.Value.ToString());

        return result;
    }

    public static string Build(object data)
    {
        string result = "";
        var dict = ToPropertyDictionary(data);
        foreach (var name in dict.Keys)
            result += name + "=" + HttpUtility.UrlEncode(dict[name]) + "&";
        return result.Substring(0, result.Length - 1);
    }
}

class Program
{
    static void Main(string[] args)
    {
        string postText = PostDataBuilder.Build(
        new
        {
            dsh = "-1903339439726094408",
            GALX = "-Ggrv6gqusk",
            timeStmp = "",
            secTok = "",
            Email = "WrongEmail@gmail.com",
            Passwd = "WrongPassword",
            signIn = "?????",
            rmShown = "1"
        });

        byte[] data = Encoding.UTF8.GetBytes(postText);

        WebClient wc = new WebClient();
        byte[] result = wc.UploadData(
            new Uri("https://accounts.google.com/ServiceLoginAuth"), 
            "POST", data);

        string resultText = Encoding.UTF8.GetString(result);
    }
}

ResultText 变量已设置,即使数据正确。怎么了?

4

1 回答 1

1

您永远不应该乱搞诸如 Google 之类的登录服务或试图伪造浏览器。最后,它可能被认为是黑客攻击或其他任何事情,并且很可能会在他们下次更新页面时中断(或者甚至只是因为您的 IP 更改)。

而是使用此处所述的 OpenID 或 OAuth 。

于 2012-07-01T17:22:29.583 回答