Solved

Reading a Web cookie from my app

Posted on 1997-05-01
3
1,110 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

Suggested Solutions

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
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…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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