Discussion:
Read a cookie with just the name
(too old to reply)
k***@hotmail.com
2006-11-01 04:19:28 UTC
Permalink
Is there a way to read a cookie by just the name without giving the
domain URL? Both CInternetSession.GetCookie and InternetGetCookie
expect domain url.

if that is not possible, is there an API or some workaround code which
loops through all the cookies no matter which domain they belong to?

Basically I just to read a cookie and get some values, but I only know
the name of the cookie and I wouldn't know the domain name.

Is it possible?

Thanks (I am NOT using .Net)
Vladimir Scherbina
2006-11-01 17:49:49 UTC
Permalink
No.

--
Vladimir
Post by k***@hotmail.com
Is there a way to read a cookie by just the name without giving the
domain URL? Both CInternetSession.GetCookie and InternetGetCookie
expect domain url.
if that is not possible, is there an API or some workaround code which
loops through all the cookies no matter which domain they belong to?
Basically I just to read a cookie and get some values, but I only know
the name of the cookie and I wouldn't know the domain name.
Is it possible?
Thanks (I am NOT using .Net)
Paul Baker [MVP, Windows - Networking]
2006-11-01 19:10:05 UTC
Permalink
I haven't actually tried it, but what about FindFirstUrlCacheEntry, etc.?

You could check CacheEntryType for each INTERNET_CACHE_ENTRY_INFO, looking
for COOKIE_CACHE_ENTRY.

Paul
Post by Vladimir Scherbina
No.
--
Vladimir
Post by k***@hotmail.com
Is there a way to read a cookie by just the name without giving the
domain URL? Both CInternetSession.GetCookie and InternetGetCookie
expect domain url.
if that is not possible, is there an API or some workaround code which
loops through all the cookies no matter which domain they belong to?
Basically I just to read a cookie and get some values, but I only know
the name of the cookie and I wouldn't know the domain name.
Is it possible?
Thanks (I am NOT using .Net)
Vladimir Scherbina
2006-11-01 14:51:36 UTC
Permalink
P.S. Don't expect the error checking code present in that example - the code
was written "just on fly" - I don't like to spend time for such things in
examples. And as I can see I also forgot to call FindCloseUrlCache and the
end of the enumeration.
--
Vladimir
Paul,
Again, the answer is No...
I made a simple example that enumerates all cookies using
FindFirstUrlCacheEntry. The problem is that INTERNET_CACHE_ENTRY_INFO
structure does not have a field that contains the cookie name.
Look at attached file: test.cpp. At the begining you will find the code
which is setting custom cookie with name ''MyCookieName". Then the
enumeration staff comes. To make things easier it's better to clean all
cookies in IE before running test.
On the other hand, I can suggest to OP the undocumented way: read the
cookie name from cookie file. The path to file can be obtained from
INTERNET_CACHE_ENTRY_INFO::lpszLocalFileName field. The cookie name is the
first line in a file. It's easy to implement but I think this will
structure will be broken in Vista.
--
Vladimir
Post by Paul Baker [MVP, Windows - Networking]
I haven't actually tried it, but what about FindFirstUrlCacheEntry, etc.?
You could check CacheEntryType for each INTERNET_CACHE_ENTRY_INFO, looking
for COOKIE_CACHE_ENTRY.
Paul
Post by Vladimir Scherbina
No.
--
Vladimir
Post by k***@hotmail.com
Is there a way to read a cookie by just the name without giving the
domain URL? Both CInternetSession.GetCookie and InternetGetCookie
expect domain url.
if that is not possible, is there an API or some workaround code which
loops through all the cookies no matter which domain they belong to?
Basically I just to read a cookie and get some values, but I only know
the name of the cookie and I wouldn't know the domain name.
Is it possible?
Thanks (I am NOT using .Net)
k***@hotmail.com
2006-11-03 09:32:42 UTC
Permalink
Thanks to both Vladimir and Paul for answering.

Yes, I finally ended up looping through all the browser cache using
FindFirstUrlCacheEntry and FindNextUrlCacheEntry. I also ended up
looking for a specific string in the cookie data to identify the
correct cookie.

Thanks again
Vladimir Scherbina
2006-11-03 13:17:31 UTC
Permalink
Keep in your mind that once vista will be shiped you will have to rewrite
your code.
--
Vladimir
Post by k***@hotmail.com
Thanks to both Vladimir and Paul for answering.
Yes, I finally ended up looping through all the browser cache using
FindFirstUrlCacheEntry and FindNextUrlCacheEntry. I also ended up
looking for a specific string in the cookie data to identify the
correct cookie.
Thanks again
Loading...