WebFormPost Function

Action

Posts the content of a Web form to the Web server by means of the HTTP POST method. If the form includes a random variable, this function selects a new random value each time the form is posted. Use the WebFormPostEx function to post two forms in the same request.

Include file

WebAPI.bdh

Syntax

WebFormPost( in sUrl     : string,
             in formBody : form,
             in fWait    : float optional ): boolean;

Return value

  • true if the worker thread posting the form content to the server could be started successfully

  • false otherwise. The return value will not inform about any Web traffic-related problems due to independent threaded operation.

Parameter Description
sUrl Complete URL to the file on the server
formBody Form identifier used in the dclform section (see example below). The expanded form is added to the body of the request. The Content-Length and Content-Type header is added automatically. The default Content-Type is application/x-www-form-urlencoded and can be overwritten by a call to WebHeaderAdd("Content-Type", "myEncoding") prior to WebFormPost.
fWait Minimum time or minimum mean time that this function call has to last (optional). Default value is 0.0

The form content in the dclform section is represented in an unencoded format to enhance readability and customizability. The data gets URL encoded on form submission. There are two possibilities to send data unencoded:

  • Add the query string as it should be sent to the server directly to the URL, for example, "http://www.comp.com/cgi/special?<don't>;[encode]/this". Note that blanks are encoded when this method is used.

  • Use WebUrlPostBin or WebFormPostBin to post data as provided to the Web server.

Example

var
  nWait : float;
  sName : string(100);

dclrand
  rnWait    : RndExpF(5.0);
  rnPhone   : RndStr("0123456789"; 16..16);
  rsAddress : RndFile("Address.rnd", 100);
  rsFName   : RndFile("gfname.rnd", 20);
  rsLName   : RndFile("glname.rnd", 20);

dcltrans
  transaction TWebFormPost
  begin
    // Get a random full name
    sName := rsFName + " " + rsLName;

    // and a random think time
    nWait := rnWait;
    WebFormPost("http://standardhost:2080/data2html.asp",
    FORM_01, nWait);
  end TWebFormPost;

dclform
  FORM_01:
    "name"    := sName,
    "address" := rsAddress,
    "phone"   := rnPhone;

Sample scripts

WebForms01.bdf, WebMeasure01.bdf, WebMulti01.bdf, WebParseResponse01.bdf, WebPost01.bdf, WebVerification01.bdf