How to build and send the web form request with the POST method

 
procedure TfmWebFormPost.btSubmitClick(Sender: TObject);   
begin   
   clHttpRequest1.Clear();   
   clHttpRequest1.AddFormField('Name', 'John Doe');   
   clHttpRequest1.AddFormField('BirthDate', '10/10/72');   
   clHttpRequest1.AddFormField('Account', '123');   
 
   clUploader1.HTTPRequest := clHttpRequest1;   
   clUploader1.UseHTTPRequest := True;   
   clUploader1.URL := 'http://www.clevercomponents.com/'   
      +'products/inetsuite/demos/serverformpost.asp';   
 
   clUploader1.Start(False);   
 
   ShowMessage(clUploader1.HttpResponse.Text);   
end;

Feedback

Add Feedback
Hello
Testing this component, it is very good. But can not to send Post data without form submnit. For example, the webpage have buttons, that at press, sending any data to server and go to the next button, but have not any form. Looking in the sniffer, can not to see PostData from Clever App, but testing form sending in the Demo, working good... Any way to send PostData without form? At add any rows, the result is 1 row like string. Thanks.

Using this code:

var
response: TStream;
action: string;
html: TStrings;
begin
if clHttp1.Active then Exit;
html := TStringList.Create();
try
html.Add('questionId=1116');
html.Add('answerId=3104');

Paulina Olalla (October 21, 2020 at 5:02 PM)
Hello,

You need to use the following two components to send Post data: TclHttp and TclHttpRequest. For sure, you can compose and send a request without having to use the TclHttpRequest component. But in such a case, you will need to compose both the request body (with your fields 'questionId' and 'answerId') and the request header, which includes some necessary HTTP headers: Content-Length, Content-Type, etc. The TclHttpRequest component does it automatically. Please check out the code below to see how it works:

var
response: TStrings;
begin
response := TStringList.Create();
try
clHttpRequest1.Clear();
clHttpRequest1.AddFormField('questionId', '1116');
clHttpRequest1.AddFormField('answerId', '3104');

clHttp1.Post('http...', clHttpRequest1, response);
finally
response.Free();
end;
end;

Sergey Shirokov (November 24, 2020 at 4:58 PM)

Add Feedback