Microsoft KB Archive/280509

From BetaArchive Wiki
Knowledge Base


Article ID: 280509

Article Last Modified on 5/11/2006



APPLIES TO

  • Microsoft Internet Explorer 5.5
  • Microsoft Internet Explorer (Programming) 5.5 SP1
  • Microsoft Internet Explorer (Programming) 5.5 SP2



This article was previously published under Q280509

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.

CAUSE

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

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.

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.

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}.

REFERENCES

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

Keywords: kbbug kbfix kbqfe kbwebbrowser KB280509