如何从c ++代码中获取cookie

时间:2017-03-03 11:43:35

标签: c++ cookies mfc

我试图让我的MFC应用程序从网站访问登录屏幕(如Spotify一样),其想法是在用户登录网站后将其重定向到另一个带有cookie的页面。

我使用派生的CDHtmlDialog类和"得到" OnNavigateComplete方法内的重定向,但IHtmlDocument2Ptr(m_spHtmlDoc)始终为null。

void CDHtmlDlgPersonalizado::OnNavigateComplete(LPDISPATCH pDisp, LPCTSTR szUrl)
{
    this->GetDHtmlDocument(&this->m_spHtmlDoc);

    if (this->m_spHtmlDoc != nullptr)
        this->m_spHtmlDoc->get_cookie(bstr);
}

如何从我的c ++代码中获取cookie?

编辑: GetDHtmlDocument在OnNavigateComplete和OnDocumentComplete中返回E_NOINTERFACE。 登录屏幕的导航是在OnInitDialog方法中进行的:

BOOL CDHtmlDlgPersonalizado::OnInitDialog()
{
    CDHtmlDialog::OnInitDialog();

    CString str(_T("http://www.MyLoginScreen.com/"));
    this->Navigate(str);

    return TRUE;
}

此代码在CDialogEx派生类中调用:

BOOL CDlgMsgBoxHtml::OnInitDialog()
{
    CDialogEx::OnInitDialog();

    VERIFY(this->m_HtmlCtrl.SubclassDlgItem(IDC_HTML, this));

    /*m_HtmlCtrl is the object to the CDHtmlDialog derived class*/

    this->m_HtmlCtrl.OnInitDialog();

    /*I also tried calling the navigate here*/
    //CString str3(_T("http://www.MyLoginScreen.com/"));
    //this->m_HtmlCtrl.Navigate(str3);

    /*But got the same results*/

    //IHTMLDocument2Ptr spHtmlDoc = nullptr;
    //this->m_HtmlCtrl.GetDHtmlDocument(&spHtmlDoc);

    return TRUE;
}

提前致谢,抱歉我的英语不好。

0 个答案:

没有答案