Delphi-Kylix
  Home arrow Delphi-Kylix arrow Simulate a Web Submit Wizard with POST Req...
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Actuate Whitepapers 
VeriSign Whitepapers 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
DELPHI-KYLIX

Simulate a Web Submit Wizard with POST Request
By: Clever Components
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 7
    2003-07-17

    Table of Contents:
  • Simulate a Web Submit Wizard with POST Request
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
    Iron Speed
     
    ADVERTISEMENT

    AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th -1:00PM EST. Register Today!

    Simulate a Web Submit Wizard with POST Request


    (Page 1 of 2 )

    Using Delphi to implement POST requests is made easy thanks to this article provided by the Clever Component Team. See how to simulate a web submit wizard today.

    Abstract

    This article introduces the easiest way to composite with Delphi/C++Builder IDE design-time HTTP Form POST requests for submitting them to the web server in the future.

    Lets go ahead and consider some web scenaries which implement some data posting from a client, data retrieving from the server specified and also require that the established connections will be kept during the whole session.

    Scenario One

    Log-in to the server in order to submit some personal information.

    This may be some kind of online registration page which usually allows you to enter the information with simple form input controls (which has the type="text" attribute specified or any other). To submit such a kind of request they usually use the "application/x-www-form-urlencoded" content type. This means that the controls for the entire page sholud be encoded while making the HTTP request as follows:

    FirstName=John&LastName=Doe

    Here both the FirstName and LastName words denote the form control names and the John and Doe words the values correspondingly. With Clever Internet Suite it is possible to make this request totally in IDE design-time without writting any lines of source code. There is a special class which represents the HTTP request data - TclHTTPRequest. Lets consider the request structure in more details. It is obvious that it consists of two similar parts i.e: field name - field value. The class TclHTTPRequest has a collection of such request parts which represent descendants of the TclHTTPRequestItem base class. You can easily create instances with any of these classes in both the IDE design-time and run-time modes.

    The screenshot below demonstrates the HTTP Request editor with two added request items.

    You can also add the request items you need in run-time. For your convenience the TclHTTPRequest class provides a set of helper functions any of which can create corresponding HTTP request item:

    • AddBinaryData
    • AddTextData
    • AddSubmitFile
    • AddFormField

    All what you require for making and submitting the HTTP requiest is to put the TclUploader component on the form and run its HTTP Request Editor dialog. In order to make the component use the HTTP request you made, you should set the UseHTTPRequest property to True and assign the URL property to a valid HTTP resource which is assigned to retrieve data submitted from a client.

    A sample of how to use the TclUploader for making and submitting the HTTP request in Delphi run-time is shown below:

    procedure TMainForm.btnStartClick(Sender: TObject);
    begin
       clUploader.URL := edtHost.Text;
       clUploader.HTTPRequest.AddFormField('FirstName', 'John');
       clUploader.HTTPRequest.AddFormField('LastName', 'Doe');
       clUploader.Start();
    end;

    Scenario Two

    Log-in to the server in order to submit some user information and some local file from a user with corresponding file description.

    A sample of this scenario can be found in our Simulate Submit Wizard web page.

    The first step of such kinds of wizards are similar to the first scenario, but on the next wizard page some controls implement the file uploading feature can be placed. This forces the client to send the request data as multipart content. So the HTTP request for the second wizard page should look similar to the sample below:

     -----------------------------7d325a200432
    Content-Disposition: form-data; name="Description"
    The file description is placed here.
    -----------------------------7d325a200432
    Content-Disposition: form-data; name="FileName"; filename="c:\sample.txt"
    Content-Type: application/octet-stream
    A sample file contents is placed here.
    -----------------------------7d325a200432--

    In order to make this request you should add two different HTTP request items - TclFormFieldRequestItem and TclSubmitFileRequestItem. On the second editor page you can set-up the HTTP request item details for the selected item. The following screenshot demonstrates the TclSubmitFileRequestItem content details.

    The third HTTP request editor page specifies the additional headers which will be sent with the request specified. Within this page you can select some predefined request types, with their additional headers and specify your own custom headers.

    Note! Please make sure that if you send the multipart requiest data, the additional headers contain the boundary header field. If you do not specify this field it may cause with some difficulties with parsing the request on the server side.

    To walk through these wizard pages from Delphi it is more preferable to use the TclMultiUploader suite component. This component allows you to set-up each Submit Wizard page on the separated uploader item.

    The sample below demonstrates how to submit multiple wizard pages with the TclMultiUploader component.

    procedure TMainForm.btnStartClick(Sender: TObject);
    var
       Item: TclUploadItem;
    begin
       if clMultiUploader.IsBusy then
       begin
          ShowMessage('Uploading is in progress');
          Exit;
       end;
       memResult.Lines.Clear();
    // Process first step
       Item := clMultiUploader.UploadList[0];
       (Item.HTTPRequest[0] as TclFormFieldRequestItem).FieldValue := edtFirstName.Text;
       (Item.HTTPRequest[1] as TclFormFieldRequestItem).FieldValue := edtLastName.Text;
       (Item.HTTPRequest[2] as TclFormFieldRequestItem).FieldValue := edtAccount.Text;
       Item.Start(False); //synchronous mode
    // Process second step
       Item := clMultiUploader.UploadList[1];
       (Item.HTTPRequest[0] as TclFormFieldRequestItem).FieldValue := edtDescription.Text;
       (Item.HTTPRequest[1] as TclSubmitFileRequestItem).FileName := edtFileName.Text;
       Item.Start(True); //asynchronous mode, when the process completed the OnStatusChanged event occur
    end;

    procedure TMainForm.clMultiUploaderStatusChanged(Sender: TObject;
       Item: TclInternetItem; Status: TclProcessStatus);
    begin
       if (Status = psSuccess) and (Item.Index > 0) then
       begin
          ShowMessage('Process completed successfully.');
       end;
    end; 

    On each step you can control the server response via the ServerResponse uploader item property which is also available within the OnGetServerResponse component event.

     procedure TMainForm.clMultiUploaderGetServerResponse(Sender: TObject;
       Item: TclInternetItem);
    begin
       memResult.Lines.Add(Format('---------- Step %d ------------', [Item.Index + 1]));
       memResult.Lines.AddStrings((Item as TclUploadItem).ServerResponse);
    end;

    The full source code of this Demo can be obtained with the Clever Internet Suite Demo installation available at Download Clever Internet Suite.

    Please try an executable version available at SubmitWizard.zip.

    Scenario Three

    Log-in to the server and download the information given by this server.

    Finally the third kind of interface between a user and a web page is used mostly in getting some authorized data from the web.

    On the first wizard page there are usually some controls placed which allow you to enter the user name and password. On the second response page some URL's may be placed to download the data.

    To simulate such a scenario all that you need is to place both the TclUploader and TclDownloader components and link them with the TclInternetConnection suite component.

    TclUploader should be configured for sending of HTTP form field items like in the First Scenario, and TclDownloader will be used for downloading internet resources via the connection being established with the TclUploader component.

    To prevent the internet components from closing the connection you should set the KeepConnection component porperty to True on both the TclUploader and TclDownloader components.

    More Delphi-Kylix Articles
    More By Clever Components


     

    DELPHI-KYLIX ARTICLES

    - Client Dataset: Working with Data Packets an...
    - Using the Client Dataset in an N-Tiered Appl...
    - Using the Client Dataset in Two-Tiered Clien...
    - Using the Client Dataset in File-Based Archi...
    - Demystifying the Client Dataset
    - Working with INI Files in Delphi
    - Creating Data Link (UDL) Files in Delphi
    - Looking at the Details for an Invoicing Appl...
    - Invoicing in Delphi: Show Me the Money
    - Saving Images and Binary Files to a Database...
    - Saving Files to a Database using Delphi: Sav...
    - Creating CF Applications and Integrating a S...
    - Using Try and Finally to Help Prevent Memory...
    - The Implementation of an FTP Server
    - FTP Server: The Theory


    Iron Speed





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway