从CDHtmlDialog获取cookie [英] Get cookie from CDHtmlDialog

查看:193
本文介绍了从CDHtmlDialog获取cookie的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的MFC应用程序中,我有一个派生的CDHtmlDialog类,该类可打开登录屏幕,并且我需要在重定向后从服务器获取url和cookie.

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.

我导航到OnInitDialog内的url,并在OnNavigateComplete内捕获重定向:

I navigate to the url inside the OnInitDialog and catch the redirect inside 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);
}

但是GetDHtmlDocument返回E_NOINTERFACE,我应该实现他吗?如果是,我如何获取IHTMLDocument2?.

but the GetDHtmlDocument is returning E_NOINTERFACE, should i implement him? if yes how do i get the IHTMLDocument2?.

所以我的问题是为什么我无法获取文档,这是获取cookie的正确方法吗?

So my question is why i can't get the document and is this the right way to get a cookie?

先谢谢您,我的英语不好.

Thank's in advance and sorry for my bad English.

推荐答案

最后弄清楚了.

在CDHtmlDialog类中,OnNavigateComplete方法负责将值分配给m_spHtmlDoc,但是由于我覆盖了该方法,因此没有人向文档分配值,甚至没有OnDocumentComplete分配值,因此简单的解决方案是

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

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);
    }
}

这篇关于从CDHtmlDialog获取cookie的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆