Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Obtain cookies from IBindCtx

98 views
Skip to first unread message

Alexander Dyagilev

unread,
Nov 1, 2009, 5:35:26 PM11/1/09
to
Hello!

How? I have pointers to IMoniker and IBindCtx interfaces.

Igor Tandetnik

unread,
Nov 1, 2009, 11:02:32 PM11/1/09
to
Alexander Dyagilev wrote:
> How [to obtain cookies from IBindCtx]? 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

Alexander Dyagilev

unread,
Nov 2, 2009, 7:25:21 AM11/2/09
to
Hello, Igor!

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.

Alexander Dyagilev

unread,
Nov 2, 2009, 7:49:29 AM11/2/09
to
OK, it seems the request is made already, but.... I implement my own
IDownloadManager. The problem is that some servers does not allow
connect twice. I use cURL in a separate process for downloading, not
standard Windows API. So I just can't download from such servers and
would like to ignore them. My users can click "Cancel" and skip the
download by my program so IE will download itself. When I use
IBindStatusCallback to get the cookies IE fails to download then I
return a error from my IDownloadManager::Download. Its download window
disappears in a second and IE does nothing to download the file.

Igor Tandetnik

unread,
Nov 2, 2009, 9:06:26 AM11/2/09
to
Alexander Dyagilev wrote:
> InternetGetCookie does not help.

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.

Alexander Dyagilev

unread,
Nov 2, 2009, 11:39:03 AM11/2/09
to
On Nov 2, 5:06 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
> Alexander Dyagilev wrote:
> > InternetGetCookie does not help.
>
> Have you tried?

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.

Igor Tandetnik

unread,
Nov 2, 2009, 12:34:27 PM11/2/09
to
Alexander Dyagilev wrote:
> On Nov 2, 5:06 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:
>> Alexander Dyagilev wrote:
>>> InternetGetCookie does not help.
> 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.

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.

Alexander Dyagilev

unread,
Nov 2, 2009, 1:53:54 PM11/2/09
to
On Nov 2, 8:34 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:

> 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?

Alexander Dyagilev

unread,
Nov 2, 2009, 2:35:43 PM11/2/09
to
I've just discovered by a sniffer that this GX cookie has 'HttpOnly'
attribute.

Igor Tandetnik

unread,
Nov 2, 2009, 2:43:00 PM11/2/09
to
Alexander Dyagilev wrote:
> 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

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.

Alexander Dyagilev

unread,
Nov 2, 2009, 2:55:48 PM11/2/09
to
On Nov 2, 10:43 pm, "Igor Tandetnik" <itandet...@mvps.org> wrote:

> 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.

Alexander Dyagilev

unread,
Nov 2, 2009, 3:39:36 PM11/2/09
to
All the information about a request is stored in IBindCtx. I think so
due the following experiment:

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.

0 new messages