Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with THTTPServer
#1
I need some help using THTTPServer under Delphi,

I am attempting to write a server that will handle some client based data forms.

I can receive the POST transaction through CommandGet, and can read the data fields passed in the RequestInfo.Params.Values data elements with no problem.

But I am totally at a loss on how to send back the new data field values to the client.

Any help would be appreciated.
Reply
#2
I recommend using web services toolkit. It works under both lazarus and Delphi.
Reply
#3
(02-03-2020, 10:19 AM)andym2 Wrote: But I am totally at a loss on how to send back the new data field values to the client.

That is a bit too broad to answer. You are going to have to be more specific. What exactly are you trying to send back, in what format, and how do you expect your client to interpret it? There is only one response, and you have to decide what format you want to send it in. Is your client a web browser? A WebSocket? A REST client?

Reply
#4
Thanks for the ideas.

I wish to stay with the Indy toolbox for Delphi.

In this example I have a Client screen developed under Expression Web, that has a form with 3 fields on it and a Submit button. I am using MS Edge as the web browser.

On the server at Submit I receive the 3 data fields, and process their data. I now want to send back data to those 3 fields for display to the user.

I had expected there to be something like the RequestInfo.Params in the ResponseInfo structure, where I can set the new field data and send back to the Client.

What am I missing here?
Reply
#5
(02-04-2020, 05:09 AM)andym2 Wrote: On the server at Submit I receive the 3 data fields, and process their data. I now want to send back data to those 3 fields for display to the user.

Is the webform being submitted to your server through a normal web post (ie, the user clicks the button, and the browser directly submits it), or is it being submitted via client-side AJAX scripting (the XMLHTTPRequest object, etc)? Or though some other means?

If the former, then send back the same HTML page containing the same webform, just with the HTML <input> fields filled in with the desired values as needed. <input> fields have attributes in their HTML for that purpose.

If the latter, then send back a JSON document containing the desired values, and let the client-side AJAX scripting parse the JSON and populate the existing webform fields via the browser's DOM interfaces as needed.

(02-04-2020, 05:09 AM)andym2 Wrote: I had expected there to be something like the RequestInfo.Params in the ResponseInfo structure, where I can set the new field data and send back to the Client.

No, because that is not how HTML and HTTP interact with each other.

(02-04-2020, 05:09 AM)andym2 Wrote: What am I missing here?

An understanding of the relationship between client-side technologies (HTML, AJAX, etc) and how they use HTTP to send and receive data. When sending data to a server, HTTP definitely defines how webform data should be posted. That is why the ARequestInfo.Params property can exist. But there is no single definitive way to send data back to a webform on a client, which is why there is nothing provided in AResponseInfo for that specific purpose.

Reply
#6
I think we are getting closer. You are correct this is just a normal web post, no scripts, AJAX or anything.

So after my processing I can call a ResponseInfo.ServeFile(AContext, 'testform.html'));. When I do the client screen is displayed but with the fields all blank.

I want to send back to the client "Field1=ABC". "Field2=XYZ" and "Field3=1234".

So where are the HTML <input> fields you refer to? I'm guessing they are somewhere in the AContext or ResponseInfo structures, but how do I set, in this example, the 3 data pairs?
Reply
#7
(02-04-2020, 10:45 PM)andym2 Wrote: I think we are getting closer. You are correct this is just a normal web post, no scripts, AJAX or anything.

Then, you can pretty much send back whatever you want, and the browser will display it. Send HTML, plain text, JSON, it is really up to you. It sounds like you probably want HTML, though.

(02-04-2020, 10:45 PM)andym2 Wrote: So after my processing I can call a ResponseInfo.ServeFile(AContext, 'testform.html'));. When I do the client screen is displayed but with the fields all blank.

You could do that, but you would have to alter the HTML after each post to fill in the webform fields with your desired values.

(02-04-2020, 10:45 PM)andym2 Wrote: I want to send back to the client "Field1=ABC". "Field2=XYZ" and "Field3=1234".

Then you have to send back HTML that has been altered after each post. For example, instead of sending a static HTML file containing:

Code:
<input type="text" name="Field1">
<input type="text" name="Field2">
<input type="text" name="Field3">

You would have to send a dynamic HTML text containing instead:

Code:
<input type="text" name="Field1" value="ABC">
<input type="text" name="Field2" value="XYZ">
<input type="text" name="Field3" value="1234">

(02-04-2020, 10:45 PM)andym2 Wrote: So where are the HTML <input> fields you refer to?

Inside the .html file you are sending to the client. In that file, there is a <form> element that tells the web browser where to submit the webform to. Non-empty <input> fields inside that <form> are what get submitted by the web browser to your server.

(02-04-2020, 10:45 PM)andym2 Wrote: I'm guessing they are somewhere in the AContext or ResponseInfo structures

No, they are not. They are in the HTML data you are sending back to the client. Sounds like you need to read up more on how HTML webforms actually work.

(02-04-2020, 10:45 PM)andym2 Wrote: how do I set, in this example, the 3 data pairs?

See above.

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)