请教关于WIN32 SDK调用IE浏览器的问题.

WIN32SDK_ASM 2014-05-21 02:17:07
已经获取网络上http文件的地址,需要调用IE(或其他浏览器)来打开(必须传递COOKIE给服务器,让它知道我是登陆的).
请问用ShellExecute能否调用IE并传递COOKIE,
或者有其他办法吗?
...全文
347 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
WIN32SDK_ASM 2014-05-29
  • 打赏
  • 举报
回复
引用 12 楼 Bokutake 的回复:
嗯,你看看你的程序的定义的targetver.h或者stdafx.h里的版本是怎么定义的。 应该是WINVER和_WIN32_WINNT之类应该是0x501,还有_WIN32_IE的版本应该是0x600。 如果使用默认的最新接口定义,可能会出问题。 还有你可以试试先Navigate about:blank,再put_cookie,然后Navigate目标 http://blog.csdn.net/charlessimonyi/article/details/17413295 另一种方法,你可以用InternetSetCookie设置持久Cookie。毕竟是跨进程的。这个需要在打开浏览器前。
InternetSetCookie可能会出问题,有的电脑调用的是360浏览器,不知道和IE是不是共COOKIE的
辰岡墨竹 2014-05-29
  • 打赏
  • 举报
回复
嗯,你看看你的程序的定义的targetver.h或者stdafx.h里的版本是怎么定义的。 应该是WINVER和_WIN32_WINNT之类应该是0x501,还有_WIN32_IE的版本应该是0x600。 如果使用默认的最新接口定义,可能会出问题。 还有你可以试试先Navigate about:blank,再put_cookie,然后Navigate目标 http://blog.csdn.net/charlessimonyi/article/details/17413295 另一种方法,你可以用InternetSetCookie设置持久Cookie。毕竟是跨进程的。这个需要在打开浏览器前。
WIN32SDK_ASM 2014-05-26
  • 打赏
  • 举报
回复
引用 8 楼 Bokutake 的回复:
赵老师又说了一堆话呢。正确的调用IE并获取接口写cookie的方法是(没用VC调试,不过逻辑上应该没问题):

if (SUCCEEDED(OleInitialize(NULL))) {
    IWebBrowser2* pBrowser = NULL;
 
    CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                       IID_IWebBrowser2, (void**)&pBrowser);
    if (pBrowser != NULL) {
        VARIANT vEmpty;
        VariantInit(&vEmpty);

        BSTR bstrURL = SysAllocString(L"http://microsoft.com/");

        HRESULT hr = pBrowser->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);

        if (SUCCEEDED(hr)) {
            pBrowser->put_Visible(VARIANT_TRUE);
 
            IDispatch* pDisp;
            pDisp = pBrowser->get_Document();
            IHTMLDocument2* pDocument2;

            hr = pDisp->QueryInterface(IID_IHTMLDocument2, (PVOID*)&pDocument2);

            if (SUCCEEDED(hr)) {
                BSTR bstrCoookie = SysAllocString(L"");
                hr = pDocument2->put_cookie(&bstrCookie);
                if (FAILED(hr))
                    pBrowser->Quit();
                SysFreeString(bstrCookie);
                pDocument2->Release();
            }
            else {
                pBrowser->Quit();
            }
            pDisp->Release();
        }
        else {
            pBrowser->Quit();
        }
        SysFreeString(bstrURL);
        pBrowser->Release();
    }

    OleUninitialize();
}
hr = pBrowser2->get_Document(&pDisp); 返回的hr为E_NOTIMPL Not implemented. 而且HRESULT hr = pBrowser->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);就直接打开了浏览器,根本来不及PUTCOOKIE
WIN32SDK_ASM 2014-05-25
  • 打赏
  • 举报
回复
引用 8 楼 Bokutake 的回复:
赵老师又说了一堆话呢。正确的调用IE并获取接口写cookie的方法是(没用VC调试,不过逻辑上应该没问题):

if (SUCCEEDED(OleInitialize(NULL))) {
    IWebBrowser2* pBrowser = NULL;
 
    CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                       IID_IWebBrowser2, (void**)&pBrowser);
    if (pBrowser != NULL) {
        VARIANT vEmpty;
        VariantInit(&vEmpty);

        BSTR bstrURL = SysAllocString(L"http://microsoft.com/");

        HRESULT hr = pBrowser->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);

        if (SUCCEEDED(hr)) {
            pBrowser->put_Visible(VARIANT_TRUE);
 
            IDispatch* pDisp;
            pDisp = pBrowser->get_Document();
            IHTMLDocument2* pDocument2;

            hr = pDisp->QueryInterface(IID_IHTMLDocument2, (PVOID*)&pDocument2);

            if (SUCCEEDED(hr)) {
                BSTR bstrCoookie = SysAllocString(L"");
                hr = pDocument2->put_cookie(&bstrCookie);
                if (FAILED(hr))
                    pBrowser->Quit();
                SysFreeString(bstrCookie);
                pDocument2->Release();
            }
            else {
                pBrowser->Quit();
            }
            pDisp->Release();
        }
        else {
            pBrowser->Quit();
        }
        SysFreeString(bstrURL);
        pBrowser->Release();
    }

    OleUninitialize();
}
感谢,再研究研究
WIN32SDK_ASM 2014-05-25
  • 打赏
  • 举报
回复
引用 7 楼 zhao4zhong1 的回复:
[quote=引用 6 楼 zhao4zhong1 的回复:] 请通读MSDN中 Web 开发、Internet Explorer Development 这一章的内容。
请通读MSDN中 Web 开发、Internet Explorer Development、Browser Extensions 这一节的所有内容。 [/quote] 好的,感谢,我再读读
WIN32SDK_ASM 2014-05-23
  • 打赏
  • 举报
回复
引用 4 楼 zhao4zhong1 的回复:
使用WebBrowser控件 ?
纯调用IE8或者IE6,不用其他控件
赵4老师 2014-05-23
  • 打赏
  • 举报
回复
使用WebBrowser控件 ?
辰岡墨竹 2014-05-23
  • 打赏
  • 举报
回复
赵老师又说了一堆话呢。正确的调用IE并获取接口写cookie的方法是(没用VC调试,不过逻辑上应该没问题):

if (SUCCEEDED(OleInitialize(NULL))) {
    IWebBrowser2* pBrowser = NULL;
 
    CoCreateInstance(CLSID_InternetExplorer, NULL, CLSCTX_LOCAL_SERVER, 
                       IID_IWebBrowser2, (void**)&pBrowser);
    if (pBrowser != NULL) {
        VARIANT vEmpty;
        VariantInit(&vEmpty);

        BSTR bstrURL = SysAllocString(L"http://microsoft.com/");

        HRESULT hr = pBrowser->Navigate(bstrURL, &vEmpty, &vEmpty, &vEmpty, &vEmpty);

        if (SUCCEEDED(hr)) {
            pBrowser->put_Visible(VARIANT_TRUE);
 
            IDispatch* pDisp;
            pDisp = pBrowser->get_Document();
            IHTMLDocument2* pDocument2;

            hr = pDisp->QueryInterface(IID_IHTMLDocument2, (PVOID*)&pDocument2);

            if (SUCCEEDED(hr)) {
                BSTR bstrCoookie = SysAllocString(L"");
                hr = pDocument2->put_cookie(&bstrCookie);
                if (FAILED(hr))
                    pBrowser->Quit();
                SysFreeString(bstrCookie);
                pDocument2->Release();
            }
            else {
                pBrowser->Quit();
            }
            pDisp->Release();
        }
        else {
            pBrowser->Quit();
        }
        SysFreeString(bstrURL);
        pBrowser->Release();
    }

    OleUninitialize();
}
赵4老师 2014-05-23
  • 打赏
  • 举报
回复
引用 6 楼 zhao4zhong1 的回复:
请通读MSDN中 Web 开发、Internet Explorer Development 这一章的内容。
请通读MSDN中 Web 开发、Internet Explorer Development、Browser Extensions 这一节的所有内容。
赵4老师 2014-05-23
  • 打赏
  • 举报
回复
请通读MSDN中 Web 开发、Internet Explorer Development 这一章的内容。
WIN32SDK_ASM 2014-05-22
  • 打赏
  • 举报
回复
引用 2 楼 zhao4zhong1 的回复:
#include <afxinet.h> Class Members | Base Class | Hierarchy Chart Samples MFC Sample FTPTREE | MFC Sample TEAR See Also CInternetConnection, CHttpConnection, CFtpConnection, CGopherConnection
你这个解答和我的问题不符啊,而且你这个要用MFC,我想要的是调用IE打开(带COOKIE),
赵4老师 2014-05-22
  • 打赏
  • 举报
回复
CInternetSession Use class CInternetSession to create and initialize a single or several simultaneous Internet sessions and, if necessary, to describe your connection to a proxy server. If your Internet connection must be maintained for the duration of an application, you can create a CInternetSession member of the class CWinApp. Once you have established an Internet session, you can call OpenURL. CInternetSession then parses the URL for you by calling the global function AfxParseURL. Regardless of its protocol type, CInternetSession interprets the URL and manages it for you. It can handle requests for local files identified with the URL resource "file://". OpenURL will return a pointer to a CStdioFile object if the name you pass it is a local file. If you open a URL on an Internet server using OpenURL, you can read information from the site. If you want to perform service-specific (for example, HTTP, FTP, or gopher) actions on files located on a server, you must establish the appropriate connection with that server. To open a particular kind of connection directly to a particular service, use one of the following member functions: GetGopherConnection to open a connection to a gopher service. GetHttpConnection to open a connection to an HTTP service. GetFtpConnection to open a connection to an FTP service. QueryOption and SetOption allow you to set the query options of your session, such as time-out values, number of retries, and so on. CInternetSession member functions SetCookie, GetCookie, and GetCookieLength provide the means to manage a Win32 cookie database, through which servers and scripts maintain state information about the client workstation. During an Internet session, a transaction such as a search or data download can take appreciable time. The user might want to continue working, or might want to have status information about the progress of the transaction. To handle this problem, CInternetSession provides for searches and data transfer to occur asychronously, allowing the user to perform other tasks while waiting for the transfer to complete. If you want to provide the user with status information, or if you want to handle any operations asynchronously, three conditions must be set: In the constructor, dwFlags must include INTERNET_FLAG_ASYNC. In the constructor, dwContext must be set to a nonzero value. You must establish a call back function by calling EnableStatusCallback Use the overridable member function OnStatusCallback to get status information on asynchronous retrieval. To use this overridable member function, you must derive your own class from CInternetSession. For more information about asynchronous operations, see the articleInternet First Steps: WinInet in Visual C++ Programmer’s Guide. For general information about using the MFC WinInet classes, see the articleInternet Programming with WinInet in Visual C++ Programmer’s Guide. Note CInternetSession will throw an AfxThrowNotSupportedException for unsupported service types. Only the following service types are currently supported: FTP, HTTP, gopher, and file. #include <afxinet.h> Class Members | Base Class | Hierarchy Chart Samples MFC Sample FTPTREE | MFC Sample TEAR See Also CInternetConnection, CHttpConnection, CFtpConnection, CGopherConnection
WIN32SDK_ASM 2014-05-21
  • 打赏
  • 举报
回复
有大大帮忙指导下吗

65,207

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧