Scalabium Software

SMExport advertising
Knowledge for your independence'.
Home Delphi and C++Builder tips

#139: TWebBrowser and POST request

Today I want to describe how you can send some data to web-server from your remote script using TWebBrowser component.

  strData: string;
  PostData: OleVariant;
  Headers: OleVariant;
  i: Integer;
  {1. you must create a string with parameter names and values
  Result string must be in the next format:
  strData := 'Param1Name=' + HTTPEncode(Param1Value) + '&' +
    'Param2Name=' + HttpEncode(Param2Value) + ...;

  {2. you must convert a string into variant array of bytes and
   every character from string is a value in array}
  PostData := VarArrayCreate([0, Length(strData) - 1], varByte);

  { copy the ordinal value of the character into the PostData array}
  for i := 1 to Length(strData) do
    PostData[i-1] := Ord(strData[i]);

  {3. prepare headers which will be sent to remote web-server}
  Headers := 'Content-Type: application/x-www-form-urlencoded' + #10#13;

  {4. you must navigate to the URL with your script and send as parameters
  your array with POST-data and headers}
  yourWebBrowserComponent.Navigate('', EmptyParam, EmptyParam, PostData, Headers);

Of course, the same task can be solved with any internet component which implement the http-client (not only TWebBrowser). But for every component the data for script will be posted by own rules (most components have pre-defined properties for this task).

For example, you can use my TSMIHTTPClient component from SMInternet suite. There you must set Action=haPost and fill the Headers property with own Post-data.

Published: April 24, 2002

See also
SMExport suite
SMImport suite
DBExport tools
dBase Viewer
Paradox ActiveX
Protected Storage Viewer
ExcelFile Viewer

Contact to webmaster


Borland Software Code Gear Scalabium Delphi tips

Copyright© 1998-2017, Scalabium Software. All rights reserved.

SMReport Autogenerated