Discussion:
WebBrowser control - PostData fom Navigate missing in BeforeNavigate
(too old to reply)
John Austin
2004-09-09 15:46:54 UTC
Permalink
When I call the Navigate method of the WebBrowser control from VB6 sp6, the
string data that I supply in the PostData argument is missing in the
corresponding BeforeNavigate event.

I am trying to trap the result of a query generated by the user and modify
it before it is submitted.

I am using IE6 sp1

Data supplied in the URL and Headers parameters appear OK in BeforeNavigate.
--
John Austin
Peter Huang
2004-09-10 08:21:08 UTC
Permalink
Hi,

You may try the code below and let me know the result.
How To Use the PostData Parameter in WebBrowser Control
http://support.microsoft.com/?id=174923

Private Sub Command1_Click()
Dim URL As String
Dim Flags As Long
Dim TargetFrame As String
Dim PostData() As Byte
Dim Headers As String
URL = "http://YourServer" ' A URL that will accept a POST
Flags = 0
TargetFrame = ""
PostData = "Information sent to host"
' VB creates a Unicode string by default so we need to
' convert it back to Single byte character set.
'PostData = StrConv(PostData, vbFromUnicode)
Headers = "Content-Type: application/x-www-form-urlencoded" &
vbCrLf
WebBrowser1.Navigate URL, Flags, TargetFrame, PostData, Headers
End Sub

Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As
Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant,
Headers As Variant, Cancel As Boolean)
Debug.Print PostData
End Sub

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
John Austin
2004-09-10 10:47:02 UTC
Permalink
Thanks Peter, that did the trick! It also explained why I was getting a row
of question marks in PostData from user initiated navigation.

The documentation is a bit weak though - Navigate2 mentions the 'safe
array', though does not explain how to create one in VB (only in C). The
Navigate method just describes the parameter as Variant.
Post by Peter Huang
Hi,
You may try the code below and let me know the result.
How To Use the PostData Parameter in WebBrowser Control
http://support.microsoft.com/?id=174923
Private Sub Command1_Click()
Dim URL As String
Dim Flags As Long
Dim TargetFrame As String
Dim PostData() As Byte
Dim Headers As String
URL = "http://YourServer" ' A URL that will accept a POST
Flags = 0
TargetFrame = ""
PostData = "Information sent to host"
' VB creates a Unicode string by default so we need to
' convert it back to Single byte character set.
'PostData = StrConv(PostData, vbFromUnicode)
Headers = "Content-Type: application/x-www-form-urlencoded" &
vbCrLf
WebBrowser1.Navigate URL, Flags, TargetFrame, PostData, Headers
End Sub
Private Sub WebBrowser1_BeforeNavigate2(ByVal pDisp As Object, URL As
Variant, Flags As Variant, TargetFrameName As Variant, PostData As Variant,
Headers As Variant, Cancel As Boolean)
Debug.Print PostData
End Sub
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Peter Huang
2004-09-13 02:04:16 UTC
Permalink
Hi John,

I am glad that the problem is resolved, if you still have any concern
please feel free to post here.

Best regards,

Peter Huang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
Loading...