[HELP]WinINet login to facebook.com!
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Thread: [HELP]WinINet login to facebook.com!

  1. #1
    Join Date
    May 2009
    Posts
    3

    [HELP]WinINet login to facebook.com!

    I need to login to facebook, but my code doesnt work:

    #include <windows.h>
    #include <wininet.h>
    #include <string>
    #include <iostream.h>

    using namespace std;

    void main()
    {

    string m_strURL;

    HINTERNET hSession, hDownload, hRequest;

    hSession = InternetOpen("MFFS", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    hDownload = InternetConnect(hSession, "login.facebook.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

    hRequest = HttpOpenRequest(hDownload, "POST", "/login.php?login_attempt=1", NULL, NULL, NULL, INTERNET_FLAG_SECURE, 0);

    HttpSendRequest(hRequest, NULL, 0, "email=johnjohnjohn@hotmail.com&pass=123123123", 401);

    if ( hRequest )
    {
    CHAR buffer[1024];
    DWORD dwRead;
    while ( InternetReadFile( hRequest, buffer, 1023, &dwRead ) )
    {
    if ( dwRead == 0 )
    break;

    buffer[dwRead] = 0;
    m_strURL += buffer;
    cout << buffer << endl;
    }
    }
    }

    Any idea whats wrong?
    Thanks!

  2. #2
    Join Date
    Nov 2003
    Location
    Portland, OR
    Posts
    826

    Re: [HELP]WinINet login to facebook.com!

    Websites these days don't simply rely on the form fields data, there may be a host of other security measures implemented against people like you The form itself may have hidden data fields, it may use cookies and reloading of the page for repeated authentication. I'm sure, facebook uses all that as well.

  3. #3
    Join Date
    May 2009
    Posts
    3

    Re: [HELP]WinINet login to facebook.com!

    Facebook doesn't have a lot of security in the way you login... I made a script in php with curl to login to facebook, it was very easy... But with WinINet idk what is the problem:
    I dont get a msg like:
    Cookies Required

    Cookies are not enabled on your browser. Please adjust this in your security preferences before continuing.

    or

    You are using an incompatible web browser.

    or

    Incorrect Email/Password Combination

    So i fink I'm not even sending POST data....
    I used tamper data to see what is necessary to login to facebook and you only need the pass and the email (there are 4 more hidden fields like char_set passholder etc...)
    But i still cant find where is the problem :*(

  4. #4
    Join Date
    May 2009
    Posts
    3

    Re: [HELP]WinINet login to facebook.com!

    Here is the new code:
    #include <windows.h>
    #include <wininet.h>
    #include <string>
    #include <iostream.h>

    using namespace std;

    void main()
    {

    static char hdrs[] = ("Content-Type: application/x-www-form-urlencoded");
    static char frmdata[] = ("email=qiller@hotmail.com&pass=qwertyasdf");
    static LPSTR accept = ("*/*", NULL);

    string m_strURL, url;

    HINTERNET hSession, hDownload, hRequest;

    hSession = InternetOpen("MFFS", INTERNET_OPEN_TYPE_DIRECT, NULL, NULL, 0);

    hDownload = InternetConnect(hSession, "login.facebook.com", INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP, 0, 0);

    hRequest = HttpOpenRequest(hDownload, "POST", "/login.php?login_attempt=1", "HTTP/1.1", NULL, NULL, INTERNET_FLAG_SECURE, 0);

    HttpSendRequest(hRequest, hdrs, strlen(hdrs), frmdata, strlen(frmdata));

    if ( hRequest )
    {
    CHAR buffer[1024];
    DWORD dwRead;
    while ( InternetReadFile( hRequest, buffer, 1023, &dwRead ) )
    {
    if ( dwRead == 0 )
    break;

    buffer[dwRead] = 0;
    m_strURL += buffer;
    cout << buffer << endl;
    }
    }
    }


    Now the problem are cookies :P

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center