登录Gmail帐户

时间:2010-07-22 09:15:55

标签: authentication login forms-authentication gmail

我需要能够登录我的Gmail帐户,然后我会获得cookie并可以访问其他Google服务。但我无法登录我的Gmail(或任何goolgle)帐户。我在这个网站上发现了一些帖子怎么做,但没有一个对我有用。我这样做:

        string formUrl = "https://www.google.com/accounts/ServiceLoginAuth"; 
        string formParams = string.Format("Email={0}&Passwd={1}&signIn={2}&PersistentCookie={3}&GALX={4}",
            "autokuzov.top", "1QAZ2wsx", "Sign in", "yes", "CfFosrEhu-0");

        string cookieHeader;
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(formUrl);
        req.ContentType = "application/x-www-form-urlencoded";
        req.Referer = "https://www.google.com/accounts/ServiceLoginAuth";
        req.Method = "POST";

        req.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.9.2.7) Gecko/20100713 Firefox/3.6.7";
        req.AllowAutoRedirect = false;

        req.CookieContainer = new CookieContainer();
        req.Headers.Add(HttpRequestHeader.CacheControl, "no-cache=set-cookie");

        byte[] bytes = Encoding.ASCII.GetBytes(formParams);
        req.ContentLength = bytes.Length;
        using (Stream os = req.GetRequestStream())
        {
            os.Write(bytes, 0, bytes.Length);
        }
        WebResponse resp = req.GetResponse();

        using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
        {
            string s = sr.ReadToEnd();
        }

响应返回:“您的浏览器的Cookie功能已关闭。请将其打开。” 我也试过make req.Headers.Add(HttpRequestHeader.CacheControl,“no-cache = set-cookie”);但它也是不可靠的。

有人知道哪里有问题吗?

1 个答案:

答案 0 :(得分:0)

  

“您的浏览器的Cookie功能   被关闭了。请打开它。“

您可能需要在浏览器中启用第三方Cookie。某些浏览器默认关闭它们。如果您禁用第三方Cookie,则在使用Gmail管理器插件时,您会在Firefox中收到相同的警告。