Site Map Contact Us Home
E-mail Newsletter
Subscribe to get informed about
Clever Components news.

Your Name:
Your Email:
 
SUBSCRIBE
 
Previous Newsletters
 




Products Articles Downloads Order Support
Customer Portal      

Build Form Post Request

The Http Request component creates request data in any formats including "multipart/form-data", "application/www-form-urlencoded", "text/xml" or any custom format.

You can add each form value manually or extract and create them from existing HTML source, URL or HTML file with FORM controls. Overload list for the BuildFormPostRequest method allows you to specify the most used combinations of input parameters.

Submit Form Data

The BuildFormPostRequest method creates new Form Request by specifying HTML source for the following form:

Parameter1 
Parameter2

The code that does the work:

// [Delphi]
html.Add('<form name="FormPost" action="'
   + 'http://www.domain.com/submitdata.asp method="post">');
html.Add('<input type="text" name="Parameter1" value="Value 1">');
html.Add('<input type="text" name="Parameter2" value="Value 2">');
html.Add('<input type="submit" value="Submit">');
html.Add('</form>');

submitURL := clHttpRequest.BuildFormPostRequest(html);

Upload File

If you need to create a request for Uploading file to the server, simple specify HTML source for your Form and BuildFormPostRequest will do all the work for you:

File Name 

The following code creates a request for uploading file to the server:

// [Delphi]
html.Add('<form name="FormPost" action="'
   + 'http://www.domain.com/submitfile.asp method="post">');
html.Add('<input type="file" name="FileName" value="c:\uploads\filename.txt">');
html.Add('<input type="submit" value="Submit">');
html.Add('</form>');

submitURL := clHttpRequest.BuildFormPostRequest(html);

Example 1

If you have a web page with Form Data which you want to submit from your program, you can specify a link to this web page and BuildFormPostRequest will download the page, parse HTML and extract all necessary Form Parameters:

// [Delphi]
action := clHttpRequest.BuildFormPostRequest(
   'https://www.clevercomponents.com/products/inetsuite/demos/formpost.asp');

Example 2

Using HttpRequest component you can create any Web request manually by using one of the following functions:

// [Delphi]
clHttpRequest.AddFormField('Name', 'Betty');
clHttpRequest.AddFormField('Birthdate', '10/10/72');
clHttpRequest.AddSubmitFile('filename', 'c:\uploads\file.ext');
clHttpRequest.FormFields['Name'].FieldValue := 'John';

    Copyright © 2000-2024