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.

BUG: POST Navigate Call Fails If the WebBrowser Control Displays an XML Document


View products that this article applies to.

This article was previously published under Q322122

↑ Back to the top


Symptoms

If you host the WebBrowser control and display an XML document, any calls to the Navigate method or the Navigate2 method with a POST request fail.

↑ Back to the top


Cause

Internet Explorer is not successful when it tries to convert the Uniform Resource Locator (URL) to a multi-byte string. Therefore, Internet Explorer cannot recognize the protocol and the address.

↑ Back to the top


Resolution

You can work around this problem if you move to about:blank, wait for the DocumentComplete event, and then perform the POST request for the Navigate method from there. You must set a flag so that the Navigate call is not performed on every DocumentComplete event that is fired. The "More Information" section of this article contains example code for this workaround.

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

↑ Back to the top


More information

Steps to Reproduce the Behavior

  1. Create a Test.xml file, a Test.xsl file (which will be used with the Test.xml file), a Test.htm file, and a Test.asp file. Examples of all of the files follow: Test.xml
    <?xml version="1.0"?> 
    <?xml-stylesheet type="text/xsl" href="test.xsl" ?> 
    <Null>
    </Null>
    					
    Test.xsl
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
    <html>
    <body>
    <form action="http://myserver/mydirectory/test.asp" method="post">
    <input type="submit"/>
    </form>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    					
    Test.htm
    <html>
    <body>
    <form action="http://myserver/mydirectory/test.asp" method="post">
    <input type="submit"/>
    </form>
    </body>
    </html>
    					
    Test.asp
    <%@ LANGUAGE="VBSCRIPT" %>
    <HTML>
    <BODY>
    <%=now%>
    </BODY>
    </HTML>
    					
  2. Place these four files on your Web server (Myserver) in a directory that is named Mydirectory.
  3. Create a new Microsoft Visual Basic .exe project and host the WebBrowser control.
  4. Add the Form_Load load handler function with code that moves to the .xml page. A global baseURL variable is also used to make testing with a different base URL easier.
    Dim baseURL As String
    Private Sub Form_Load()
        baseURL = "http://myserver/mydirectory/"
        'WebBrowser1.Navigate baseURL + "test.htm"
        WebBrowser1.Navigate baseURL + "test.xml"
    End Sub
    					
  5. Add a button with a click handler to move to the .asp page with a POST request.
    Private Sub Command1_Click()
        Dim PostData() As Byte
        
        PostData = "Information sent to host"
        PostData = StrConv(PostData, vbFromUnicode)
        
        Dim url2 As Variant
        url2 = baseURL + "test.asp"
        WebBrowser1.Navigate url2, Null, Null, PostData, Null
    End Sub
    					
  6. Build the project and then click the Visual Basic Form button, not the button on the HTML page.

    The resulting problem is that navigation does not occur. If you change the Form_Load function to initially move to an .htm page, and then click the Form button, you see the POST navigation succeed. You also see that if you click the HTML Form button you succeed in the navigation.
  7. To apply the workaround, add a global flag to know when to run the workaround and a DocumentComplete handler to perform the actual POST navigation.
  8. Move the code in the click handler to the DocumentComplete function. And, in the click handler, move to about:blank. The code example with the workaround follows:
    Dim bFlag As Boolean
    Dim baseURL As String
    Private Sub Command1_Click()
        bFlag = True
        WebBrowser1.Navigate "about:blank"
    End Sub
    
    Private Sub Form_Load()
        baseURL = "http://myserver/mydirectory/"
        'WebBrowser1.Navigate baseURL + "test.htm"
        WebBrowser1.Navigate baseURL + "test.xml"
        bFlag = False
    End Sub
    
    Private Sub WebBrowser1_DownloadComplete()
        If bFlag Then
            bFlag = False
            Dim PostData() As Byte
            
            PostData = "Information sent to host"
            PostData = StrConv(PostData, vbFromUnicode)
            
            Dim url2 As Variant
            url2 = baseURL + "test.asp"
            WebBrowser1.Navigate url2, Null, Null, PostData, Null
        End If
    End Sub
    					

↑ Back to the top


Keywords: KB322122, kbwebbrowser, kbpending, kbbug, kbautomation

↑ Back to the top

Article Info
Article ID : 322122
Revision : 2
Created on : 5/12/2003
Published on : 5/12/2003
Exists online : False
Views : 421