请问:使用IE内核编写浏览器时,有没有什么方法可以得到IE发送的http请求信息

解决方案 »

  1.   

    用VC从WebBrowser组件中得到简单点说
    就是自己用CHtmlView编写了一个浏览器,想要得到发送的http头信息
      

  2.   

    做IE的插件, IE的浏览器控件由很多事件,其中之一是BeforeNavigate, 其中一个参数是请求包的数据.  如果不行,则用BHO,看Msdn的这篇文章 Browser Helper Objects: The Browser the Way You Want It 
    msdn2.microsoft.com/en-us/library/bb250436.aspxHandling Internet Explorer Events in a BHO In IEHelper's implementation of the SetSite method, IEHelper advises Internet Explorer that it wants to receive all the  
    events that Internet Explorer fires. To receive events from Internet Explorer, you must implement the IDispatch interface. By default, simple ATL objects inherit from IDispatchImpl, so you can use AtlAdvise to have Internet Explorer alert you 
    when it fires events. The only IDispatchImpl method that you must override to receive events is the Invoke method.  
    Internet Explorer will call your Invoke method each time it fires an event. To stop receiving events, you can call the AtlUnadvise method. When Internet Explorer informs you that it is quitting,  
    you call AtlUnadvise by passing DISPID_QUIT to the Invoke method. The following code overrides the Invoke method. As you can 
     see, a lot of this code is for handling the Internet Explorer events and writing their names to the IEHelper events window. STDMETHODIMP CIEHlprObj::Invoke(DISPID dispidMember, REFIID riid, 
                                    LCID lcid, WORD wFlags, 
                                    DISPPARAMS* pDispParams, 
                                    VARIANT* pvarResult, 
                                    EXCEPINFO*  pExcepInfo, UINT* puArgErr) 

       USES_CONVERSION; 
       strstream strEventInfo;    if (!pDispParams) 
          return E_INVALIDARG;    // 
       // Get the current URL. 
       //   
       LPOLESTR lpURL = NULL; 
       m_spWebBrowser2->get_LocationURL(&lpURL);    switch (dispidMember) 
       { 
          // 
          // The parameters for this DISPID are as follows: 
          // [0]: Cancel flag  - VT_BYREF ¦VT_BOOL 
          // [1]: HTTP headers - VT_BYREF ¦VT_VARIANT 
          // [2]: Address of HTTP POST data  - VT_BYREF ¦VT_VARIANT  
          // [3]: Target frame name - VT_BYREF ¦VT_VARIANT  
          // [4]: Option flags - VT_BYREF ¦VT_VARIANT 
          // [5]: URL to navigate to - VT_BYREF ¦VT_VARIANT 
          // [6]: An object that evaluates to the top-level or frame 
          //      WebBrowser object corresponding to the event  
          // 
          case DISPID_BEFORENAVIGATE2: 
             strEventInfo  < < "BeforeNavigate2: ";          if (pDispParams->cArgs >= 5 && 
                 pDispParams->rgvarg[5].vt == (VT_BYREF ¦VT_VARIANT)) 
             { 
                CComVariant varURL(*pDispParams->rgvarg[5].pvarVal); 
                varURL.ChangeType(VT_BSTR);             strEventInfo  < < OLE2T(varURL.bstrVal); 
             } 
             else 
                strEventInfo  < < "NULL";          strEventInfo  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: URL navigated to - VT_BYREF ¦VT_VARIANT 
          // [1]: An object that evaluates to the top-level or frame 
          //      WebBrowser object corresponding to the event  
          // 
          case DISPID_NAVIGATECOMPLETE2: 
             if (pDispParams->rgvarg[0].vt == (VT_BYREF ¦VT_VARIANT)) 
             { 
                CComVariant varURL(*pDispParams->rgvarg[0].pvarVal); 
                varURL.ChangeType(VT_BSTR); 
       
                strEventInfo  < < "NavigateComplete2: " 
                              < < OLE2T(varURL.bstrVal) 
                              < < ends; 
             } 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: New status bar text - VT_BSTR 
          // 
          case DISPID_STATUSTEXTCHANGE: 
             LPOLESTR lpStatusText;          m_spWebBrowser2->get_StatusText(&lpStatusText); 
             strEventInfo  < < "StatusTextChange: ";          if (!strcmp(OLE2T(lpStatusText), "")) 
                strEventInfo  < < "NULL"; 
             else 
                strEventInfo  < < OLE2T(lpStatusText);          strEventInfo  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: Maximum progress - VT_I4 
          // [1]: Amount of total progress - VT_I4 
          // 
          case DISPID_PROGRESSCHANGE: 
             strEventInfo  < < "ProgressChange: ";          if (pDispParams->cArgs == 0) 
                strEventInfo  < < "NULL"; 
             else 
             { 
                if (pDispParams->rgvarg[0].vt == VT_I4) 
                   strEventInfo  < < pDispParams->rgvarg[0].lVal;             if (pDispParams->cArgs > 1 && 
                    pDispParams->rgvarg[1].vt == VT_I4) 
                { 
                   strEventInfo  < < ", "  < < pDispParams->rgvarg[1].lVal; 
                } 
             }          strEventInfo  < < ends; 
             break;       case DISPID_DOCUMENTCOMPLETE: 
             strEventInfo  < < "DocumentComplete"  < < ends; 
             break;       case DISPID_DOWNLOADBEGIN: 
             strEventInfo  < < "DownloadBegin"  < < ends; 
             break;       case DISPID_DOWNLOADCOMPLETE: 
             strEventInfo  < < "DownloadComplete"  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: Enabled state - VT_BOOL 
          // [1]: Command identifier - VT_I4 
          // 
          case DISPID_COMMANDSTATECHANGE: 
             strEventInfo  < < "CommandStateChange: ";          if (pDispParams->cArgs == 0) 
                strEventInfo  < < "NULL"; 
             else 
             { 
                if (pDispParams->rgvarg[0].vt == VT_BOOL) 
                { 
                   strEventInfo  < < ((pDispParams->rgvarg[0].boolVal ==  
                                     VARIANT_TRUE) ? "True" : "False"); 
                }             if (pDispParams->cArgs > 1 && 
                    pDispParams->rgvarg[1].vt == VT_I4) 
                { 
                   strEventInfo  < < ", "  < < pDispParams->rgvarg[1].lVal; 
                } 
             }          strEventInfo  < < ends; 
             break;       case DISPID_NEWWINDOW2: 
             strEventInfo  < < "NewWindow2"  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: Document title - VT_BSTR 
          // 
          case DISPID_TITLECHANGE: 
             strEventInfo  < < "TitleChange: ";          if (pDispParams->cArgs > 0 && 
                 pDispParams->rgvarg[0].vt == VT_BSTR) 
             { 
                strEventInfo  < < OLE2T(pDispParams->rgvarg[0].bstrVal); 
             } 
             else 
             { 
                strEventInfo  < < "NULL"; 
             }          strEventInfo  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: Name of property that changed - VT_BSTR 
          // 
          case DISPID_PROPERTYCHANGE: 
             strEventInfo  < < "PropertyChange: ";          if (pDispParams->cArgs > 0 && 
                 pDispParams->rgvarg[0].vt == VT_BSTR) 
             { 
                strEventInfo  < < OLE2T(pDispParams->rgvarg[0].bstrVal); 
             } 
             else 
             { 
                strEventInfo  < < "NULL"; 
             }          strEventInfo  < < ends; 
             break;       // 
          // The parameters for this DISPID: 
          // [0]: Address of cancel flag - VT_BYREF ¦VT_BOOL 
          // 
          case DISPID_QUIT: 
             strEventInfo  < < "Quit"  < < ends;          ManageConnection(Unadvise); 
             m_dlgEvents.DestroyWindow(); 
             break;       default: 
             strEventInfo  < < "Unknown Event"  < < dispidMember  < < ends; 
             break; 
       }    m_dlgEvents.AddEventToList(strEventInfo.str());    return S_OK;  } 
      

  3.   

    BeforeNavigate2 获得的不是所有的 http 头,要获得所有的 http 头可以利用 Asynchronous Pluggable Protocols 或者 hook WinINet 的函数.