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

查看:16
本文介绍了从 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天全站免登陆