Solved

Reading a Web cookie from my app

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now