473,769 Members | 4,010 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using Navigate2 to add Custom HTTP Header

Hello,

I am developing a BHO that should add a custom HTTP header on a
specific domain only. Don't want the header globally, otherwise I
could just add a registry key.

So, on BEFORENAVIGATE2 , I am canceling the current navigation and
renavigating with the new custom header using Navigate2. This usually
works fine, but in some cases (particularly when selecting a link that
starts a new window), the Navigate2 call fails.

Running out of ideas, so any help would be greatly appreciated!

Here is my current code to add custom headers (yes, it's in C++/ATL but
a .NET/C# solution would be just as helpful, thanks.)

Note, this code fails with Navigate2 returning HRESULT 0x80004005.

Any ideas?

---

STDMETHODIMP CBho::Invoke(DI SPID dispidMember, REFIID riid, LCID lcid,
WORD wFlags,
DISPPARAMS* pDispParams, VARIANT* pvarResult,
EXCEPINFO* pExcepInfo, UINT* puArgErr)
{
if (!pDispParams)
return E_INVALIDARG;

switch (dispidMember)
{

case DISPID_BEFORENA VIGATE2:
{
CComQIPtr<IWebB rowser2, &IID_IWebBrowse r2> WebBrowser;
WebBrowser = pDispParams->rgvarg[6].pdispVal;
CW2CT pszUrl(pDispPar ams->rgvarg[5].pvarVal->bstrVal);
CStdString strUrl( (LPCTSTR)pszUrl );

// This is an "action cancelled" page. After the renav, we
sometimes
// get a brief action cancelled page showing up before the final
// renavigated page. Just block it so it doesn't appear at all.
if (strUrl.Right(1 2).CompareNoCas e(_T("navcancl. htm")) == 0 ) {
WebBrowser->Stop(); // Sometimes Stop() re-enters here, other
times it doesn't
*V_BOOLREF(&pDi spParams->rgvarg[0]) = VARIANT_TRUE;
break;
}

if (pDispParams->rgvarg[1].vt != (VT_BYREF|VT_VA RIANT)) {
break;
}

// Is this a xyzinc.com domain page? If so, add our HTTP header.
// Note: this block adds "xyzinc-Header:" as a header to outgoing
// GET/POST requests iff "xyzinc.com " is the target domain
if (WebBrowser && m_spWebBrowser2 == WebBrowser) {

CUrl url;
if (url.CrackUrl( (LPCTSTR)pszUrl ) == FALSE) {
break;
}

CStdString strHostName ( url.GetHostName () );

// Is this an "xyzinc.com " url
int lenxyzinc = ( strHostName.Get Length() > 11 ) ? 11 :
strHostName.Get Length();
if (strHostName.Ri ght(lenxyzinc). CompareNoCase(
_T(".xyzinc.com ") ) != 0)
break; // not our domain - don't add header

// Dig out the aleady specifed headers. Note, this is only
// new headers added specifically by a "Navigate2( )" call.
// The standard headers from the registry are not included.
CComVariant varHEADERS(*pDi spParams->rgvarg[1].pvarVal);
varHEADERS.Chan geType(VT_BSTR) ;
CW2CT pszHeaders( varHEADERS.bstr Val );
// This call is recursive, so we'll get back here again after
// the header is added. So, check if we already added the
header
// and abort everything if this is the second call.
if ( strlen(pszHeade rs) == 0 || strstr(pszHeade rs,
"xyzinc-Header:") == NULL ) {

// Now we know this is a page to add "xyzinc-Header:" to and
// that this is the first of two calls (recursive).
// So, the way to do it is (1) stop the current navigate.
// (2) reissue a new navigate keeping all params the same
// except adding our "xyzinc-Header:" header.

// Stop the original navigation immediately so it does not
// have enough time to show. Canceling a nav requires
// a "Stop()" call plus returning "TRUE" in the cancel param.
WebBrowser->Stop();
ATLASSERT(V_VT( &pDispParams->rgvarg[0]) == (VT_BOOL |
VT_BYREF)); // Just in case
*V_BOOLREF(&pDi spParams->rgvarg[0]) = VARIANT_TRUE;

// Now, specify our header and renav. But first, make sure
// we add our header to any existing headers passed in.
CComVariant vtHeaders;
CStdString strHeader;
strHeader.Forma t("%sxyzinc-Header: %s\r\n",
(LPCTSTR)pszHea ders, (LPCTSTR)m_pszM yHeader);
vtHeaders = strHeader.c_str ();

// Note PostData argument passes pvarVal->pvarVal.
Otherwise,
// postdata is dropped and forms loose the data during a
post.
HRESULT hr = WebBrowser->Navigate2( &pDispParams->rgvarg[5],
&pDispParams->rgvarg[4], &pDispParams->rgvarg[3],
(pDispParams->rgvarg[2].pvarVal)->pvarVal, &vtHeaders );
if (FAILED(hr)) {
LOGFAILURE("Nav igate2() failed HRESULT=%x", hr);
// !!!!!! THIS FAILS
// with HRESULT=0x80004 005
}
}
}
}

Jun 15 '06 #1
0 3735

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3227
by: Tobias Hesselmann | last post by:
Hi folks, i have a problem using a PHP script as a custom handler in Apache. What i wanna do is this: Whenever a .html file is requested by a browser, i want Apache to call a CGI that outputs a header, then the requested file and then a footer. I want to use PHP for this, as i also want to do some template parsing. Well, basically, this can be done using Apache's mod_action module,
0
1680
by: mic | last post by:
I'm stuck with following problem. Using webbrowser control I try to make custom-made request. I found working example of this written in VBS but porting it to Python doesn't seem to work. The key is navigate (or navigate2) method, that accepts PostData as one of it's parameters. As stated in reference: "The post data specified by PostData is passed as a SAFEARRAY Data Type structure. The variant should be of type Array and point to a...
1
3578
by: Kevin | last post by:
Hi, My application is a MDI and for each document, I create a WebBrowser control and call Navigate2 to get the HTML view of each document. I have tried opened two documents and Navigate2 to the same ASP page. I find that I get the same sessionId of these two view and the data of these two documents are screwed up. Do you know why the two WebBrowser controls have the same session id? (is
3
9869
by: Tim Bücker | last post by:
Hello. I am trying to launch the internet explorer from my program using the code seen below but unfortunately the Navigate2 command is ignored. So Navigate2 is not working but calling GoHome() the start page is being displayed...??? Has someone an idea what I am doing wrong? Here´s the code:
4
14559
by: Matthew Roche | last post by:
Greetings: I am developing an application that uses an ASP.NET Web Forms application for its UI and ASP.NET web services for its business tier, and I am looking for assistance in improving my application security. I want to use declarative security on my web methods so I can secure them more easily. In short, I want to secure the web services using the first code snippet below. Please note that the web method has a custom SOAP header....
2
567
by: asnowfall | last post by:
I am creating MailMessage out of already existing email message. My existing message has few custom properties. I wan to add them to System.Net.Mail.MailMessage How to add custom properties? I was thinking adding custom properties to System.Net.Mail.MailMessage.Headers. but it's a READONLY property. System.Net.Mail.MailMessage has few header fields as properties (eg: FROM, TO, CC) and these are not sufficient.
1
1506
by: mikeh3275 | last post by:
I have a header control that I include in my .aspx page. In this control, I'm trying to retrieve a cookie value and store it into a string, but I am receiving an "Object reference not set to an instance of an object." error. Below is the code. Any help is appreciated. Thanks. .aspx page: <%@ Page Language="C#" AutoEventWireUp=true CodeFile="OrderAdmin.aspx.cs" Inherits="_Default" %> <%@ Reference...
5
2080
by: zhang | last post by:
error C3861: 'Navigate2': identifier not found why???
3
2426
by: skcsknathan001 | last post by:
I have 2 projects, and accessing a custom control , fron another project. Inside the custom control, it calls a function It compiles and when it runs I get a NullReference error message on the function which accepts the ImageButton. Basically custom control is called .. goes into execute functions, but the ImageButton control inside the custom control is not passed to the function. I'm thinking is it some permission blocking the visibility...
0
9423
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
1
9995
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9863
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7410
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5304
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3962
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3563
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.