views:

73

answers:

1

Hi, folks, I need to be able to login to my gmail account, then i get cookies and will have access to other google services. But i can't login to my gmail(or any goolgle) account. I found some posts on this site how to do it, but none works for me. i do :

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

Response return : "Your browser's cookie functionality is turned off. Please turn it on." I also tried make req.Headers.Add(HttpRequestHeader.CacheControl, "no-cache=set-cookie"); but it was unseccussfull too.

Does anybody know where is a problem ?

A: 

"Your browser's cookie functionality is turned off. Please turn it on."

You will probably need to have 3rd party cookies enabled in your browser. These are off by default in some browsers. You get the same warning in Firefox when using the Gmail Manager plugin if you disable 3rd party cookies.

w3d
How can i enable 3rd party cookies in C# when i am making request to my google account.
Dzmitry
You certainly can't if you are running this from your web server, within the browser. Only the user can do this manually for security reasons. If you are running this as an external application, then may be.
w3d