[C++] Login to facebook with WinINet!

Posted on 2009-05-28
Medium Priority
Last Modified: 2012-06-27
I'm making an application for and i need to check if a login is valid for facebook. POST request works fine, there is no problem with https but I seems like WinINet doesnt use cookies!
Do you have any idea how to resolve this problem?
#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;
	HINTERNET hSession, hDownload, hRequest;
	hSession = InternetOpen("DFBAC", 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 )
			buffer[dwRead] = 0;
			cout << buffer << endl;
			m_strURL += buffer;

Open in new window

Question by:avivshabo
  • 2
  • 2
LVL 86

Accepted Solution

jkr earned 1500 total points
ID: 24495174
You have to set your cookie data manually using 'InternetSetCookie()'(http://msdn.microsoft.com/en-us/library/ms918378.aspx) - see also http://msdn.microsoft.com/en-us/library/aa385326(VS.85).aspx ("Managing Cookies")
BOOL bReturn;
// Create a session cookie.
bReturn = InternetSetCookie("http://www.adventure_works.com", NULL,
            "TestData = Test");
// Create a persistent cookie.
bReturn = InternetSetCookie("http://www.adventure_works.com", NULL,
           "TestData = Test; expires = Sat,01-Jan-2000 00:00:00 GMT");

Open in new window


Author Comment

ID: 24495314
Is there a way to set the cookie automatically?
Thanks anyway ;)

Author Comment

ID: 24495354
Sorry i didnt got it, it was THE solution, just need to add:
InternetSetCookie("https://login.facebook.com/login.php?login_attempt=1",  NULL,  "test_cookie=1;");

Open in new window

LVL 86

Expert Comment

ID: 24495364
No, sorry - you get the data transmitted after you log on and that data is what you use for that API call. See http://msdn.microsoft.com/en-us/library/aa384321.aspx ("HTTP Cookies") for more about cookies and how they're transmitted.

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Many modern programming languages support the concept of a property -- a class member that combines characteristics of both a data member and a method.  These are sometimes called "smart fields" because you can add logic that is applied automaticall…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

600 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question