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

How do I add cookies to IWebBrowser2::Navigate ?

1,524 views
Skip to first unread message

Paul Bradford

unread,
May 3, 2001, 9:46:18 PM5/3/01
to
I'd like to add cookies when I call IWebBrowser2::Navigate.
For example:
SHDocVw::IWebBrowser2Ptr spBrowser;//already created
_variant_t vtEmpty;
_bstr_t bstrURL;// already set to valid URL;
_variant_t vCookie(_bstr_t("Cookie: foo = bar"));

spBrowser->Navigate
(
bstrURL,
&vtEmpty/*flags*/,
&vtEmpty/*frame*/,
&vtEmpty/*post data*/,
&vCookie/*headers*/
);

The cookie I set does not appear on the server. I assume that the
syntax I'm passing to the 'headers' argument of Navigate is incorrect,
but I see no documentation about exactly how to set 'headers'.

When I monitor the IE event BeforeNavigate2, it shows the 'header'
argument, which includes some garbled version of the characters I
put in vCookie.

Any help will be appreciated.

Thanks,

Paul Bradford

Sean

unread,
May 5, 2001, 1:03:52 AM5/5/01
to
Check out this kb Q240191.

Thanks,

Sean Shi

Paul Bradford

unread,
May 6, 2001, 12:02:00 AM5/6/01
to
"Sean" wrote in message ...

>Check out this kb Q240191.
>
>Thanks,
>
>Sean Shi

Hi Sean,

That's an interesting article, but unfortunately it doesn't solve my
particular
problem. The article talks about setting a cookie in an ASP session
from code running on the server.

My problem is to set a cookie on a client before the HTTP GET takes
place, so that the ASP code will see the cookie. I'm pretty sure that
the 'headers' argument to IWebBrowser2::Navigate will let me
do this, but I can't figure out the syntax of the 'headers' argument.

Thanks,

Paul Bradford


Sean

unread,
May 8, 2001, 4:53:16 PM5/8/01
to
lets talk about the BeforeNavigate2(
IDispatch *pDisp,
VARIANT *URL,
VARIANT *Flags,
VARIANT *TargetFrameName,
VARIANT *PostData,
VARIANT *Headers,
VARIANT_BOOL *Cancel).

The Headers is type of VT_BYREF | VT_VARIANT.

Also use network monitor to check whether the cookie is sent out.


Paul Bradford

unread,
May 8, 2001, 5:39:45 PM5/8/01
to

"Sean" wrote in message ...

I set a breakpoint in BeforeNavigate2 and look at Headers. It contains
some of the characters from the 'headers' parameter in my call to
IWebBrowser::Navigate, but it's all garbled. There is something
about my 'headers' parameter to Navigate that is not correct, but
I don't know what.

What exactly should the 'headers' argument to IWebBrowser2::Navigate
look like?

Paul


Sean

unread,
May 8, 2001, 7:22:03 PM5/8/01
to
HRESULT Navigate(
BSTR URL,

VARIANT *Flags,
VARIANT *TargetFrameName,
VARIANT *PostData,
VARIANT *Headers
);


and the Headers type will be the same as the one in Navigate2.
VT_BYREF|VT_VARIANT.
You can say it is a pointer to a variant.
How about this in MFC for example:

CString strCookie;
COleVariant* pvarCookie = new COleVariant( strCookie );

Similar thing in ATL.

Paul Bradford

unread,
May 8, 2001, 7:56:28 PM5/8/01
to

"Sean" wrote in message ...

My question doesn't have to do with the type of the
'headers' argument, it has to do with the contents.
It is a string - how do I format it? I've tried lots
of variations of
"Cookie: foo=bar"
and none of them work. What exactly is the syntax?

Igor Tandetnik

unread,
May 8, 2001, 9:33:20 PM5/8/01
to
See RFC 2109. The óookie header is rather complex:

cookie = "Cookie:" cookie-version
1*((";" | ",") cookie-value)
cookie-value = NAME "=" VALUE [";" path] [";" domain]
cookie-version = "$Version" "=" value
NAME = attr
VALUE = value
path = "$Path" "=" value
domain = "$Domain" "=" value

For example:

Cookie: $Version="1"; Customer="WILE_E_COYOTE"; $Path="/acme"

$Version parameter is mandatory-- With best wishes, Igor Tandetnik

"Paul Bradford" <paulbr...@alum.mit.edu> wrote in message
news:9d9iud$sf9$1...@bob.news.rcn.net...

Sean

unread,
May 8, 2001, 11:26:46 PM5/8/01
to
What do you mean by syntax? syntax for bstr or the cookie?
For bstr, you can use:

BSTR myBstr = SysAllocString("yourCookieString");
VARIANT varMyVariant;
varMyVariant..vt = VT_BSTR;
varMyVariant.bstrVal = myBstr;

let me know whether that helps.

Sean


Paul Bradford

unread,
Jun 6, 2001, 3:36:27 PM6/6/01
to
"Paul Bradford" <paulbr...@alum.mit.edu> wrote in message
news:9csjgo$93p$1...@bob.news.rcn.net...

> I'd like to add cookies when I call IWebBrowser2::Navigate.
> For example:
> SHDocVw::IWebBrowser2Ptr spBrowser;//already created
> _variant_t vtEmpty;
> _bstr_t bstrURL;// already set to valid URL;
> _variant_t vCookie(_bstr_t("Cookie: foo = bar"));
>
> spBrowser->Navigate
> (
> bstrURL,
> &vtEmpty/*flags*/,
> &vtEmpty/*frame*/,
> &vtEmpty/*post data*/,
> &vCookie/*headers*/
> );
>
> The cookie I set does not appear on the server. I assume that the
> syntax I'm passing to the 'headers' argument of Navigate is incorrect,
> but I see no documentation about exactly how to set 'headers'....

In case anybody is interested, I went through Microsoft support
to find out more about this. Their answer: what I want to do is
not supported. The 'headers' argument to Navigate/Navigate2
CANNOT be used to set cookies. There is no way to set cookies
for an IWebBrowser2 object.

I consider this a bug, but what I think is unlikely to change anything :)

We solved my problem in a completely different way.


Sean

unread,
Jun 6, 2001, 6:05:40 PM6/6/01
to
Thanks for your reply.

Sean Shi

0 new messages