Solved

Reading a Web cookie from my app

Posted on 1997-05-01
3
1,107 Views
Last Modified: 2013-12-04
Hi,

I'm trying to read a cookie written by script embedded in an HTML page from a C++ application. I tried to use the InternetGetCookie() function (defined in wininet.h) but it always fails. GetLastError() returns the value:
ERROR_NO_MORE_ITEMS
which winerror.h defines as: "No more data is available." Presumably I'm giving this function an incorrect parameter but after trying every combination I could think of, nothing works.

I've checked the actual cookie directory and the cookie data does get written. I can write the code to read it myself  but I’d like to avoid the hassle. Also, I'm afraid that the cookie format may change.

I'm using VC++ 5 and IE4.
Any help would be appreciated.

Dan
0
Comment
Question by:shappir
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
emmons earned 200 total points
ID: 1397053
SInce you are getting ERROR_NO_MORE_ITEMS, I assume that you are failing to match any cookies in the cache (in the absence of your code+the cookie this is a start)
So, according to the spec, the URL matches if and only if:

* both host names are IP addresses and their host name
  strings match exactly; or

* both host names are FQDN strings and their host name strings
   match exactly; or

* A is a FQDN string and has the form NB, where N is a
  non-empty name string, B has the form .B', and B' is a FQDN
  string.  (So, x.y.com domain-matches .y.com but not y.com.)

This last one is the one that caught me. Do you have the request beginning with a period?

The parameters to the function are straightforward other than the syntax of the URL,
BOOL InternetGetCookie(
      IN LPCSTR lpszUrlName,
      IN LPCSTR lpszCookieName,
      OUT LPSTR lpszCookieData,
      IN OUT LPDWORD lpdwSize );

and lpszCookieName should be NULL.
0
 

Expert Comment

by:dcass
ID: 13530169
Is this c#?  It won't compile and I have the same problem.  I'm new at this though.
Where are the variables?  i.e. where is the cookie data if I do get it to compile?
0
 
LVL 4

Expert Comment

by:emmons
ID: 13630315
No, it is not c#.  The answer was from 1997!
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

808 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