You are currently offline, waiting for your internet to reconnect

How To Use the PostData Parameter in WebBrowser Control

This article was previously published under Q174923
SUMMARY
The WebBrowser control has a Navigate method with PostData as a parameter.This allows the user to post data to the specified URL with the WebBrowsercontrol.
MORE INFORMATION
Navigate specifications:
Navigates to the resource identified by a Universal Resource Locator (URL), or to the file identified by a full path.

Syntax:
   object.Navigate URL [Flags,] [TargetFrameName,] [PostData,] [Headers]				

PostData Optional:

Data to send to the server during the HTTP POST transaction. For example,the POST transaction is used to send data gathered by an HTML form. If thisparameter does not specify any post data, the Navigate method issues anHTTP GET transaction. This parameter is ignored if URL is not an HTTP URL.

NOTE: The post data specified by PostData is passed as a SAFEARRAYstructure. The variant should be of type VT_ARRAY and point to a SAFEARRAY.The SAFEARRAY should be of element type VT_UI1, dimension one, and have anelement count equal to the number of bytes of post data.

Sample to PostData to URL server

  1. Start Visual Basic. If Visual Basic is already running, choose New Project from the File menu (ALT, F, N). Form1 is created by default.
  2. Add a WebBrowser control (WebBrowser1) to Form1.
  3. Add a CommandButton (Command1) to Form1.
  4. Add the following code to the Command1_Click event of Form1:
          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						
  5. Press the F5 key to run the program and the information in the PostData variable will be sent to the server specified in the URL parameter.
POST Navigate kbdsi kbDSupport kbVBp kbVBp500 kbVBp600 kbIndetDev400 kbIE300 kbIE301 kbIE302 kbIE400 kbIE401
Properties

Article ID: 174923 - Last Review: 08/18/2005 18:01:00 - Revision: 3.2

  • Microsoft Internet Explorer 4.01 128-Bit Edition
  • Microsoft Internet Explorer 4.0 128-Bit Edition
  • Microsoft Internet Explorer 3.02
  • Microsoft Internet Explorer 3.01
  • Microsoft Internet Explorer 3.0
  • Microsoft Visual Basic 6.0 Professional Edition
  • Microsoft Visual Basic 6.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Enterprise Edition
  • Microsoft Visual Basic 5.0 Control Creation Edition
  • Microsoft Visual Basic 4.0 16-bit Enterprise Edition
  • Microsoft Visual Basic 4.0 32-Bit Enterprise Edition
  • Microsoft ActiveX SDK
  • Microsoft Internet Client Software Development Kit 4.0
  • Microsoft Internet Client Software Development Kit 4.01
  • kbhowto KB174923
Feedback