Board index » cppbuilder » put_cookie does not set cookie
Tim Chemaly
![]() CBuilder Developer |
put_cookie does not set cookie2004-01-28 07:39:08 PM cppbuilder65 Hi I;ve loaded a simple html doc using the Navigate2 method of TCppWebBrowser. This displays fine. After loading the doc I try to set the cookie value using put_cookie which SUCCEEDS but when I read the cookie value again with get_cookie I get NULL??? I'm using XP and IE6. void __fastcall TForm1::Button4Click(TObject *Sender) { AnsiString res; try { AddCookie=true; CookieName="Hello"; CookieValue="World; path=/; domain=localhost;"; wb->Navigate2(&(TVariant)AnsiString("http://localhost/test/info.htm"),VT_EMP TY,VT_EMPTY,VT_EMPTY,VT_EMPTY); } catch(const Exception &e) { ShowMessage(e.Message); } } void __fastcall TForm1::wbDocumentComplete(TObject *Sender, LPDISPATCH pDisp, TVariant *URL) { if (AddCookie) { AddCookie=false; ChangeDocumentProperties(CookieName+"="+CookieValue, wb->Document); } } //-------------------------------------------------------------------------- - void TForm1::ChangeDocumentProperties(AnsiString cookie, IDispatch* pDisp) { IHTMLDocument2* pHTMLDocument2=(IHTMLDocument2*)pDisp; BSTR h; AnsiString cs; BSTR bstr_cookie = SysAllocString(WideString(cookie.c_str()).Detach()); if ( FAILED(pHTMLDocument2->put_cookie( bstr_cookie )) ) ShowMessage("Could not set Cookie!"); if (FAILED(pHTMLDocument2->get_cookie(&h))) ShowMessage("Unable to get cookie"); cs=h; SysFreeString(bstr_cookie); } In this case cs is ALWAYS NULL! Changing CookieValue to just "World;" does not work either. Cookies are enabled as well as session cookies in IE6 Regards Tim |