unable to login to facebook

This is a discussion on unable to login to facebook within the C# Programming forums, part of the General Programming Boards category; Hello Everyone My first post here! I've been struggeling with facebook the whole evening. I'm unable to login with it. ...

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    unable to login to facebook

    Hello Everyone

    My first post here!

    I've been struggeling with facebook the whole evening. I'm unable to login with it. It just redirects me to the front site, not replying wrong password or anything.

    Here's the code:
    Code:
                string strUserName = "the%40email.com;// Properties.Settings.Default.facebookemail;
                string strPassword = "password";// Properties.Settings.Default.facebookpassword;
    
                // Get startpage and login
                string strPostData = String.Format("email={0}&pass={1}&login=Login", strUserName, strPassword);
    
                request = WebRequest.Create("https://login.facebook.com/login.php?m=&next=http%3A%2F%2Fm.facebook.com%2Fhome.php") as HttpWebRequest;
                request.Method = "POST";
                request.ContentLength = strPostData.Length;
                request.ContentType = "application/x-www-form-urlencoded";
                request.AllowAutoRedirect = true;
                request.CookieContainer = new CookieContainer();
                request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3";
                
                ASCIIEncoding encoding = new ASCIIEncoding();
                byte[] loginDataBytes = encoding.GetBytes(strPostData);
                request.ContentLength = loginDataBytes.Length;
                Stream stream = request.GetRequestStream();
                stream.Write(loginDataBytes, 0, loginDataBytes.Length);
    
                HttpWebResponse webResp = (HttpWebResponse)request.GetResponse();
                
    
                Stream datastream = webResp.GetResponseStream();
                StreamReader reader = new StreamReader(datastream);
                myFile = File.CreateText("C:\\t.txt");
                myFile.Write(reader.ReadToEnd());
    
                foreach (Cookie cook in webResp.Cookies)
                {
                    MessageBox.Show(cook.Name+" "+cook.Value);
                }
    
                
                myFile.Close();
    Anyone have an idea why?
    I've made som wireshark traces and it seems that after login is done it checks the session:

    151 11.906270 192.168.1.8 69.63.176.67 HTTP GET /checkcookie.php?r8476606e=&next=http%3A%2F%2Fwww.f acebook.com%2F&refid=9&m_sess=581326628%3A10951669 85 HTTP/1.1

    and the cookie sent is:
    Cookie: datr=1232160427-4e8b9f0fd2e204bc689bf42bf9660d84400e8024a94ed3d965 381; made_write_conn=1232160427; cur_max_lag=20; m_user=the%40email.com%3A581326628%3AkCjgUPBi6ODv6 aLr\r\n

    Thereafter a 301 to facebook.com then sv.facebook.com is received.

    Any help would be appreciated!

    Best regards,
    Marcus

  2. #2
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    The behavior from facebook seems right. The URL you are opening processes the login request and then redirects the user to the main page.

    What I would do is to get Fiddler and look at what your browser is sending and receiving so that you know what your program should be receiving.

    BTW it is generally a bad idea to post cookie data. I don't know how well facebook protects against cookie stealing.

  3. #3
    Registered User
    Join Date
    Jan 2009
    Posts
    2

    Thumbs up

    Hello Thantos!

    Thank's alot for your reply!

    I could not find any differences using Fiddler, i'm afraid. But after changin the connection URL to just https://login.facebook.com it got returned that there was no cookies activated.

    Strange, I define the cookies before request is sent. However, with a new cookiecontainer each time. No doubt that it didn't work!

    Defining the cookiecontainer on startup solved the problem! Guess that i'm not that sharp (trying to be funny) with c# yet..

    Thank you for your help!

    Best regards,
    marcus

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    1
    hi all!

    I'm a blonde!
    I can't understand your manipulations with C# code
    If it's not complicated write a complite code))))

  5. #5
    Registered User
    Join Date
    Mar 2010
    Posts
    1
    I turned over to use facebook mobile.. and browse that

    Working perfectly ^^

    but you inspired me thanks !

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Login
    By brietje698 in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2007, 09:51 AM
  2. Having problems with a login script...
    By Junior89 in forum C++ Programming
    Replies: 6
    Last Post: 01-06-2006, 11:05 AM
  3. Login
    By cgod in forum Windows Programming
    Replies: 3
    Last Post: 02-18-2005, 03:07 PM
  4. login script - URGENT!!!
    By linzeeuk in forum C Programming
    Replies: 5
    Last Post: 05-05-2003, 02:26 PM
  5. Replies: 7
    Last Post: 07-19-2002, 11:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21