A Lazarus app to receive HTTP POSTs

This is very rough… but ready, up to a point. Not good enough for you? You can stop reading at any time! (^_^)


Okay. I’m not very proficient in a LOT of what’s involved here.

Maybe you aren’t, either?

If some of what I have to say is “obvious” to you, I am very happy for you. Skim. I think you may come to things you did NOT know. I hope so, anyway.

And if you were a novice, too, and this helped, a “thank you” would be MUCH appreciated. I really only write these things for my own reference later. I DREAM that maybe they help people from time to time. But virtually no one says “thank you”, so I polish them up for a different reader as time goes on.


Know Lazarus? Know a bit about HTTP servers? Want to try something said to be a path to something to “collect” things sent to a LAN or web-attached “box”?

I suspect the code I am going to write about would also compile and run on a Linux box, but I’m working in Windows 10, 27 Aug 22, with Lazarus

The start of this was my post at…

https://forum.lazarus.freepascal.org/index.php?topic=60397.msg451549#msg451549

This arose from that, and there may be new help there from after this was posted.


Set up a “parent” folder for your work with one app’s code.

Go to the following, which was recommended in the above forum discussion.

https://github.com/alrieckert/freepascal/tree/master/packages/fcl-web/examples/httpserver

Arrange things on your screen so that you can see the left side of the browser window and a part of the File Explorer window

The Browser window should look a bit like the File Explorer window. In it, you should see…

simplehttpserve.lpi
simplehttpserver.pas

In the bad old days, downloading things was pfaff. Today (27 Aug 22), I THOUGHT I only had to drag the two filenames from the bowser window to the local folder to get the job was done. It appeared to work. I said “I guess SOME change is progress.”

NOT. All I did was put two shortcuts on my machine. (The icons made that clear. And they really were only shortcuts.

Eventually I got copies of the two files by pfaff…

… put text in file on screen in browser

…select it

…switch to text editor

…paste… Save… being careful to use .lpi and .pas extensions.

(You’re now done with your browser for a while.)


Assuming you have Lazarus set up on your machine, double-click the .lpi file. That should launch Lazarus and load the project for your attention.

Tried Run/ Quick Compile. (It doesn’t do very much, but if it won’t work, nothing else will work either. Get its problems resolved. Walk before you try to run.)

Got “simplehttpserver.pas(10,49) Fatal: Cannot find wmecho used by simplehttpsever…”

Post….
https://forum.lazarus.freepascal.org/index.php?topic=40511.0
… of March 2017 says he/she had the same problem… but just remming out the ,wmecho “fixed” (or so he thought!) the problem. (He had “other” problems later, though.) (Code I was using was datestamped 2016.) I’m hoping that “mecho” is something that only Linux people need.


After I’d done that,
It Just Ran!
*** (^^) (^^) ***

It ran (On Windows, from within the Lazarus IDE) as a simple “console program”. Nothing wrong with that… but you may not be familiar with them. It will also run on if you double-click on the listing for the .exe file in File Explorer, or on a shortcut that points to it. These latter two will work on any machine the .exe is on. You don’t need the IDE to run console apps.

This one… as most do, I think, runs from a single .exe file. (It may need support files… “config” files, etc. I’m pretty sure the program will WRITE files, once I get further down the road.)


I say “it ran”, I mean a command prompt window opened, and, repeatedly, the line “Idle, waiting for connections” was added to the window, with a newline between each instance.

This made sense. Was what I would expect to see.

Before I can make more progress, I need to organize several things… in particular, I need to provide something that tries to send HTTP POSTS to the server.

And I need to figure out how to tell that POST maker WHERE to send them.

Neither is beyond a human’s wit. But they will have to be projects for another day.

The line…

Serv.Port:=8080;

… in simplehttpserver.pas will almost certainly be involved.

Also in simplehttpserver.pas, the line…

Serv.BaseDir:=ExtractFilePath(ParamStr(0));

… suggests that when the program is launched, it will use a command line parameter (CLP), if one is provided. It may be that the program will run just fine without it. It may also be that if no CLP is provided, the files created(?) by simplehttpserver.pas will go in the folder the .exe is in.

<<Hasty, incomplete, but maybe helpful(?) notes end… for now. I tend to concentrate on things I am TOLD are useful.>>