Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

FIX: POST Data Is Truncated When You Call IWebBrowser2::Navigate


Symptoms

When you call the IWebBrowser2::Navigate method to POST binary data, the data is truncated when it encounters a NULL (0) byte in Internet Explorer 5.5.

↑ Back to the top


Cause

Internet Explorer 5.5 incorrectly interprets 0 byte as end-of-stream, which is even with binary data.

↑ Back to the top


Resolution

To work around this problem, use WinInet to post the data. For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
165298 HOWTO: Simulate a Form POST Request Using WinInet
The Navigate2 method must be performed separately without posting data. This may necessitate changes to the server-side logic.

↑ Back to the top


Status

Microsoft has confirmed that this is a bug in the Microsoft products that are listed at the beginning of this article.

This bug was corrected in Internet Explorer 5.5 Service Pack 2 and Internet Explorer 6.0.

↑ Back to the top


More information

The following code sample tries to call IWebBrowser2::Navigate to POST data:
	VARIANT vFlags = {0};
	VARIANT vPostData = {0};

	// Test data length.
	int len = 6;

	// Create test data.
	char* data = new char[len];

	// Copy a string, including its NULL character.
	memcpy(data, "hello", len);
	data[2] = '\0';
	// The data now contains {he\0lo\0}. There is an embedded NULL character. 

	// Put data into safe array.
	LPSAFEARRAY psa = SafeArrayCreateVector(VT_UI1, 0, len);
	if (!psa)
		return;
	LPSTR pPostData;
	HRESULT hr=SafeArrayAccessData(psa, (LPVOID*)&pPostData);
	memcpy(pPostData,data,len);
	hr = SafeArrayUnaccessData(psa);

	// Package the SafeArray into a VARIANT.
	V_VT(&vPostData) = VT_ARRAY | VT_UI1;
	V_ARRAY(&vPostData) = psa;         
	
	// Get Headers.
	VARIANT vHeaders = {0};
	V_VT(&vHeaders) = VT_BSTR;         

	// Specify a binary Content-Type.
	V_BSTR(&vHeaders) = SysAllocString(
		L"Content-Type: application/octet-stream\r\n"
		L"Content-Encoding: gzip\r\n");

	// Navigate, and POST the data. http://myserver/myasp.asp 
	// is an Active Server Pages page that expects POST data.
	// m_pBrowserApp is declared as IWebBrowser2*
	hr = m_pBrowserApp->Navigate(L"http://myserver/myasp.asp", &vFlags, 
		NULL, &vPostData, &vHeaders);
				
In Internet Explorer 5.5, the target page receives only 2 bytes, {he} instead of receiving the expected 6 bytes {he\0lo\0}.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Article Info
Article ID : 280509
Revision : 4
Created on : 1/1/0001
Published on : 1/1/0001
Exists online : False
Views : 166