Link to home
Start Free TrialLog in
Avatar of tdomega
tdomega

asked on

Getting cookies from the InternetExplorer

Hi,

Im writing a little webclient for http-sites. I want to use the cookies from InternetExplorer(6.0) since that is used as the main browser...
I need to get the cookies somehow. I tried it with InternetGetCookie, but it alwys fails. (returns false, but no errorcode). I also played with CInternetSession::GetCookie() but the same.

So how do I get all the cookies on site may have set from the InternetExplorers cache without knowing the name of the cookie?
And a second question, if i want to get subdomains, do i have to send the cookie from the topdomain too?

Thanks for any help :)


-Stephan
Avatar of Svetlin_Panayotov
Svetlin_Panayotov

You can try searching the cookie directory - it is different in Win9x/NT - and retrieving the names from there.It can be a somehow complicated - you must check OS version, logged user etc. and then construct your path.After you get the names InternetGetCookie() seems to be working fine with them.

Svetlin
Avatar of tdomega

ASKER

I tried it with the function InternetGetCookie(url,cookiename,cookiedata,size);

when I used it from VisualBasic it worked (was some years ago though) now it doesnt from c++.
And I dont think I need the cookie name (didnt need it under VB either)  since the msdn says  lpszCookieName : [in] Not implemented. So this function should actually get me all cookies from this site (did so in VB). So now Im wondering why it worked at that time but now fails under c++?
How does it fail? please post some code.
Maybe it's related to tihs: http://support.microsoft.com/default.aspx?scid=kb;en-us;306354
Avatar of tdomega

ASKER

Hi,

solved it :)

was a dumb error...the url InternetGetCookie wants has to start with http:// and i just used www.google.com.

sorry, my bad...
Thanks for all your help.
           LPTSTR lpData = new char[512];
            ZeroMemory(lpData,sizeof(lpData));
            DWORD dwSize = 512;
            BOOL bResult;
            bResult = InternetGetCookie("https://www.experts-exchange.com",NULL,lpData,&dwSize);
            if (!bResult)
            {
                  DWORD errCode = GetLastError();
                  printf("An error occured: %d", errCode);
            }
            else
            {
                  printf("Cookie data: %s\n",lpData);
            }
            getch();
            delete[] lpData;

The code above works well for me and retrieves the cookie.
Svetlin
Sorry sometimes the page doesn't refresh - couldn't see you solved it.
tdomega, you'll have to post a question in 'Community Support' TA in order to close the question.
https://www.experts-exchange.com/Programming/Programming_Languages/Dot_Net/VisualC_PLUS_PLUS_DOT_NET/help.jsp#hi70
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial