[英]Get cookie from CDHtmlDialog
In my MFC application i have a derived CDHtmlDialog class that opens a login screen and i need to get a url and a cookie from the server after a redirect. 在我的MFC应用程序中,我具有派生的CDHtmlDialog类,该类可打开登录屏幕,并且我需要在重定向后从服务器获取url和cookie。
I navigate to the url inside the OnInitDialog and catch the redirect inside OnNavigateComplete: 我导航到OnInitDialog内的url,并捕获OnNavigateComplete内的重定向:
void CDMYHtmlDlg::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
BSTR *bstr = nullptr;
this->GetDHtmlDocument(&this->m_spHtmlDoc);
if (this->m_spHtmlDoc != nullptr)
this->m_spHtmlDoc->get_cookie(bstr);
}
but the GetDHtmlDocument is returning E_NOINTERFACE, should i implement him? 但是GetDHtmlDocument返回E_NOINTERFACE,我应该实现他吗? if yes how do i get the IHTMLDocument2?. 如果是,我如何获取IHTMLDocument2?
So my question is why i can't get the document and is this the right way to get a cookie? 所以我的问题是为什么我无法获取文档,这是获取Cookie的正确方法吗?
Thank's in advance and sorry for my bad English. 在此先感谢您,我的英语不好。
Finally figured it out. 终于想通了。
Inside the CDHtmlDialog class the OnNavigateComplete method is responsible for assigning value to m_spHtmlDoc but since i overwritten the method no ones assign value to the document, not even the OnDocumentComplete so the simple solution is 在CDHtmlDialog类内部,OnNavigateComplete方法负责将值分配给m_spHtmlDoc,但是由于我覆盖了该方法,因此没有人向文档分配值,甚至没有给OnDocumentComplete分配值,因此简单的解决方案是
void CDHtmlDlgPersonalizado::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
/*CALL THE PARENT METHOD*/
CDHtmlDialog::OnNavigateComplete(pDisp, szUrl);
/*Now GetDHtmlDocument will get the value from m_spHtmlDoc and assign to spHtmlDoc*/
IHTMLDocument2Ptr spHtmlDoc = nullptr;
this->GetDHtmlDocument(&spHtmlDoc);
if (spHtmlDoc != nullptr)
{
BSTR bstr = ::SysAllocString(L" ");
spHtmlDoc->get_cookie(&bstr);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.