[C++] Login to facebook with WinINet!

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?
Thanks!
#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 )
			break;
		
			buffer[dwRead] = 0;
			cout << buffer << endl;
			m_strURL += buffer;
		}
	}
}

Open in new window

LVL 2
avivshaboAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

jkrCommented:
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

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
avivshaboAuthor Commented:
Is there a way to set the cookie automatically?
Thanks anyway ;)
0
avivshaboAuthor Commented:
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

0
jkrCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.