#1 2017-03-21 13:26:45

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Simulate Web Form Post Response

I'm using 'SynCrtSock' unit and trying  to simulate the data submit action occured on "Submit" button click.
This code uses the HTTP POST method to send a data to web server specified, but unfortunately, I couldn't
get the response body. Any idea?

var
  fClient: TWinHTTP;
  URI: TURI;
  URL: RawUTf8;
  FHeader, FData: SockString;
  response: TMemoryStream;
begin
  URL := 'http://www.clevercomponents.com/products/inetsuite/demos/serverformpost.asp';
  URI.From(URL);

  response := TMemoryStream.Create();
  try
    fClient := TWinHTTP.Create(URI.Server, URI.Port, false);
    if fClient.Request('/products/inetsuite/demos/serverformpost.asp?insite=1', 'POST', 0, '',
      'Name=Mr.AB&Birthdate=May+5%2C+1985&Account=12345',
      'Content-Type: application/x-www-form-urlencoded', FHeader, FData) = 200 then begin
      response.Write(fHeader[1], length(fHeader));
      response.Position := 0;
      Memo1.Lines.LoadFromStream(response);
    end;
  finally
    response.Free;
    fClient.Free;
  end;

The expect result would be:
(*
Sent data:
Name = Mr.AB
Birthdate = May 5, 1985
Account = 12345
*)

How to get the response body?

Offline

#2 2017-03-21 16:32:42

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Simulate Web Form Post Response

In FData?

So you can just use:

  Memo1.Lines.Text := UTF8ToString(FData);

No need to use a stream!

Offline

#3 2017-03-21 19:22:29

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Simulate Web Form Post Response

No, the same response using stream.

I get the content (the source code) of the of the page.
view-source:http://www.clevercomponents.com/products/inetsuite/demos/serverformpost.asp

I would like to get this response:

Sent data:
Name = Mr.AB
Birthdate = May 5, 1985
Account = 12345

Offline

#4 2017-03-21 19:37:00

ab
Administrator
From: France
Registered: 2010-06-21
Posts: 14,182
Website

Re: Simulate Web Form Post Response

I don't understand what you mean...

Offline

#5 2017-03-21 22:16:40

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Simulate Web Form Post Response

I've got the following response: http://pastebin.com/raw/wpzPZdfx   (see the page is renderized)

The response using https://www.hurl.it/ is:
See the response picture See this image before page render

Offline

#6 2017-03-22 13:11:09

warleyalex
Member
From: Sete Lagoas-MG, Brasil
Registered: 2013-01-20
Posts: 250

Re: Simulate Web Form Post Response

I have to use the inherited method Post instead of the Request... and it worked as expected! Thanks a lot.

Offline

Board footer

Powered by FluxBB