Microsoft KB Archive/322122

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

Article ID: 322122

Article Last Modified on 5/12/2003

-

APPLIES TO


 * Microsoft Internet Explorer (Programming) 5.5 SP2
 * Microsoft Internet Explorer (Programming) 6.0

-



This article was previously published under Q322122



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.



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.



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 &quot;More Information&quot; section of this article contains example code for this workaround.



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



Steps to Reproduce the Behavior
  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

    Test.xsl

    </xsl:template> </xsl:stylesheet> Test.htm

<form action=&quot;http://myserver/mydirectory/test.asp&quot; method=&quot;post&quot;> <input type=&quot;submit&quot;/> Test.asp

<%@ LANGUAGE=&quot;VBSCRIPT&quot; %> <HTML> <BODY> <%=now%> </BODY> </HTML> </li> <li>Place these four files on your Web server (Myserver) in a directory that is named Mydirectory.</li> <li>Create a new Microsoft Visual Basic .exe project and host the WebBrowser control.</li> <li> 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 = &quot;http://myserver/mydirectory/&quot; 'WebBrowser1.Navigate baseURL + &quot;test.htm&quot; WebBrowser1.Navigate baseURL + &quot;test.xml&quot; End Sub </li> <li> 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 = &quot;Information sent to host&quot; PostData = StrConv(PostData, vbFromUnicode) Dim url2 As Variant url2 = baseURL + &quot;test.asp&quot; WebBrowser1.Navigate url2, Null, Null, PostData, Null End Sub </li> <li>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.</li> <li>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.</li> <li> 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 &quot;about:blank&quot; End Sub

Private Sub Form_Load baseURL = &quot;http://myserver/mydirectory/&quot; 'WebBrowser1.Navigate baseURL + &quot;test.htm&quot; WebBrowser1.Navigate baseURL + &quot;test.xml&quot; bFlag = False End Sub

Private Sub WebBrowser1_DownloadComplete If bFlag Then bFlag = False Dim PostData As Byte PostData = &quot;Information sent to host&quot; PostData = StrConv(PostData, vbFromUnicode) Dim url2 As Variant url2 = baseURL + &quot;test.asp&quot; WebBrowser1.Navigate url2, Null, Null, PostData, Null End If End Sub </li></ol>

Keywords: kbautomation kbbug kbpending kbwebbrowser KB322122

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.