locked
winInet apis for mobile to authenticate google accounts. RRS feed

  • Question

  • Hi all,
              i have been trying to post a header to google server to accept the userid and password(new bie for WInINEt) but it is failing at httpsendRequest() with error 997 ...plz help me in overcoming this problem....,,,
    int
     SessisionInitialize()
    {
    	HINTERNET    hOpen,hConnect,hOpenReq;
    	BOOL hSendReq,bAddReqHeaders,bQueryinfo;
    	DWORD dwQbufflen;
    	wchar_t
     lplpszAcceptTypes[500] = TEXT("accountType=GOOGLE&Email=avinashreddyk@gmail.com&Passwd=198728&service=lh2&source=SOFT-Campic-1.05"
    );
    	wchar_t
     strHeader [1024];// = {TEXT("Content-type: application/x-www-form-urlencoded\r\naccountType:GOOGLE\r\nEmail:avinashreddyk@gmail.com\r\nPasswd:123456\r\nservice:cl\r\nsource=Gulp-CalGulp-1.05\r\n"),NULL};
    
    	wchar_t
     lpvQueryBuff[500];
    	hOpen = InternetOpen(TEXT("A WinHTTP Example Program/1.0"
    ), INTERNET_OPEN_TYPE_DIRECT , TEXT("www.google.com/accounts"
    ), NULL, INTERNET_FLAG_ASYNC);
    	if
    (hOpen)
    		hConnect = InternetConnect( hOpen, TEXT("www.google.com/accounts/ClientLogin"
    ), INTERNET_DEFAULT_HTTPS_PORT, NULL, NULL, INTERNET_SERVICE_HTTP,NULL,10);
    
    	//hOpenUrl = InternetOpenUrl()
    
    	if
    (hConnect)
            hOpenReq = HttpOpenRequest( hConnect, L"POST"
    , L"/accounts/ClientLogin"
     , L"HTTP/1.0."
    , NULL,  
                                        NULL, INTERNET_FLAG_KEEP_CONNECTION, 0);
    		
    		int
     chk = GetLastError();
    
    	
    	::wcscat(strHeader,L"Content-type: application/x-www-form-urlencoded"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	::wcscat(strHeader,L"accountType:GOOGLE"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	::wcscat(strHeader,L"Email:avinashreddyk@gmail.com"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	::wcscat(strHeader,L"Passwd:123456"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	::wcscat(strHeader,L"service:lh2"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	::wcscat(strHeader,L"source:soft-campic-1.0"
    );	
    	::wcscat(strHeader,L"\r\n"
    );
    	
    	if
    (hOpenReq)
    		bAddReqHeaders = HttpAddRequestHeaders(hOpenReq, strHeader, -1L, HTTP_ADDREQ_FLAG_ADD );	
    	chk = GetLastError();
    	if
    (bAddReqHeaders)
    		hSendReq = HttpSendRequest(hOpenReq, TEXT("Content-type: application/x-www-form-urlencoded"
    ), 500, 
    		                 TEXT("accountType=GOOGLE&Email=avinashreddyk@gmail.com&Passwd=198728&service=lh2&source=LGSOFT-CAMPICS-1.0"
    ), 1000);
    		
    		chk = GetLastError();
    	if
    (hSendReq)
    		bQueryinfo=	HttpQueryInfo(hOpenReq, HTTP_QUERY_CONTENT_LENGTH | HTTP_QUERY_FLAG_NUMBER, 
    											(LPVOID &)lpvQueryBuff,& dwQbufflen, NULL);
    		 chk = GetLastError();
    	if
    (hSendReq)
    		MessageBox(NULL, TEXT("Testing"
    ), TEXT("Chk the Ryt"
    ), MB_OK);
    	else
    
    		return
     0;
    
    please go thru the above code and assist me...and i need to do it in win32 only......My Primary aim is to get the login token from the server once my authentication is done...if any sample code is there please do provide that as it may be helpful....


    thanks in Advance
    Avinash REddy

    Whenever I find the key to success, someone changes the lock.
    Friday, December 4, 2009 5:44 AM