How? I have pointers to IMoniker and IBindCtx interfaces.
Would InternetGetCookie[Ex] work for you?
Alternatively, you can query IBinding (which you get in your implementation of IBindStatusCallback) for IWinInetHttpInfo and call QueryInfo(HTTP_QUERY_SET_COOKIE). That should give you raw Set-Cookie: headers that came with the response.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not necessarily a good idea. It is hard to be sure where they are going to land, and it could be dangerous sitting under them as they fly overhead. -- RFC 1925
InternetGetCookie does not help.
And I can't use IBindStatusCallback because this will allow to get
cookies only after the connection to a server. But it's required for
me to not connect to server twice. A small experiment shown me that
cookies are stored in IBindCtx, not in IMoniker.
Have you tried? What makes you believe so?
> And I can't use IBindStatusCallback because this will allow to get
> cookies only after the connection to a server.
Where exactly do you expect cookies to come from, if not from the server? Or are you talking about cookies sent to the server as part of the request?
> But it's required for
> me to not connect to server twice. A small experiment shown me that
> cookies are stored in IBindCtx, not in IMoniker.
Neither. Cookies are handled transparently by WinInet, which maintains a machine-wide (for persistent cookies) and a process-wide (for session cookies) cookie stores, and automatically saves the cookies from responses and attaches them to requests. InternetGetCookie[Ex] reads from these stores.
Unfortunately, yes.
> What makes you believe so?
It does not return all the cookies for the specified URL. Really
Internet Explorer sends more cookies as InternetGetCookie returns.
InternetGetCookie seems to not return the cookies valid for the
current session only. E.g. downloading an attachment from a web mail.
With the cookies I get from InternetGetCookie I can download an
login.php page only instead of the real file.
> > And I can't use IBindStatusCallback because this will allow to get
> > cookies only after the connection to a server.
>
> Or are you talking about cookies sent to the server as part of the request?
Yes, I am talking about the request cookies.
> Neither. Cookies are handled transparently by WinInet, which maintains a machine-wide (for persistent cookies) and a process-wide (for session cookies) cookie
> stores, and automatically saves the cookies from responses and attaches them to requests. InternetGetCookie[Ex] reads from these stores.
Unfortunately this does not help. It seems the cookies are not known
for WinInet at the moment I trying to get them.
Are you calling it from a different process, by any chance? Session cookies are maintained per-process. GetInternetCookie does retrieve session cookies, in my experience (in fact, I've just checked it again - it does work), but you have to call it from the same process where the session is.
> Unfortunately this does not help. It seems the cookies are not known
> for WinInet at the moment I trying to get them.
Request cookies came from some earlier response. They must be in WinInet's cookie jar - there's no other place to keep them.
> Are you calling it from a different process, by any chance? Session cookies are maintained per-process. GetInternetCookie does retrieve session cookies, in my experience (in fact, I've just checked it again - it does work), but you have to call it from the same process where the session is.
I call it from the Internet Explorer process, in
IDownloadManager::Download. But it does not retrieve all cookies. E.g.
GMail account. It gets all cookies except GX=SOME_LONG_TEXT_VALUE(i
think it's for authorization purposes). Where can I get this GX cookie
from? Without it my program downloads servicelogin page only. I tried
to get cookies for the domain and for the referrer's URL - did not
help.
> Request cookies came from some earlier response.
Yes, I think so too. But how can I get them? The other my version is
that cookies may be set for URL by the script of a page when I click
on download link?
Ah. It should have occured to me earlier. This cookie is marked httpOnly - see
http://msdn.microsoft.com/en-us/library/aa384321.aspx
I don't know of any way to programmatically access HttpOnly cookies. Well, I suppose in principle you could watch all requests and responses passing through, like a network sniffer does, and maintain your own cookie jar.
> I don't know of any way to programmatically access HttpOnly cookies.
They can be accessed via IBindStatusCallbak - as I do now. But this is
not suitable for me due to the reasons I've described above.
IMoniker *pmk2;
CreateURLMoniker (NULL, L"http://127.0.0.1/fakeurl.tmp", &pmk2);
pmk2->BindToStorage (pbc, NULL, IID_IStream, (void**)&spStream);
The request is still made to the original valid URL. So IMoniker's
info is ignored and I even do not know for what it's provided in
IDownloadManager::Download.