Jump to content

Recommended Posts

Posted

This is yet another HTTP server written in AutoIt3.

Originally based on jvanegmond's POST HTTP Server.

It is designed to be used either as is, or by scripts for a HTTP communication between any browser and AutoIt3.

It can run PHP and AutoIt3 CGI, if setup in the settings ini file.

Github repository

AutoIt-HTTP-Server-master.zip

  • 4 years later...
Posted

Hello can anyone please explain where i can get the POST request data that the browser sends to the server?

I have made the following example index.au3 wich displays a string a date picker and a submit button. When i press the post button the server gets the post request and i see the post key:data pair in the scite debug window, but how do i read it from withing the target au3 script that i call cmd.au3?

I tryed to read the server code but its to complex for me.

ConsoleWrite("X-Powered-By: AutoIt/"&@AutoItVersion&@LF)
ConsoleWrite("Content-type: text/html; charset=window-1252"&@LF)
ConsoleWrite(@LF)

ConsoleWrite("<html>")
ConsoleWrite("<head>")
ConsoleWrite("</head>")
ConsoleWrite("<body>")

ConsoleWrite("<h1>This is a test</h1>")

ConsoleWrite('<form action="/cmd.au3"  method="post">'  & _
                '<input type="date" id="ch_date" name="ch_date" value="John">'  & _
                '<input type="submit" value="Submit">'  & _
            '</form>')

ConsoleWrite("</body>")
ConsoleWrite("</html>")

And this is what i get in console when i press the submit:

(0067) Server created on http://0.0.0.0:80/ +0ms
(0076) Accepted new request on position: 0 +4799ms
(0086) (800)Getting request information on position: 0 +4800ms
(0099) String(600): POST / HTTP/1.1
Host: localhost
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:137.0) Gecko/20100101 Firefox/137.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate, br, zstd
Referer: http://localhost/
Content-Type: application/x-www-form-urlencoded
Content-Length: 18
Origin: http://localhost
DNT: 1
Connection: keep-alive
Upgrade-Insecure-Requests: 1
Sec-Fetch-Dest: document
Sec-Fetch-Mode: navigate
Sec-Fetch-Site: same-origin
Sec-Fetch-User: ?1
Priority: u=0, i

ch_date=2025-04-01 +4801ms
(0110) Starting processing request on position: 0 +4801ms
(0635) aUri[Path]: / +4802ms

As i can see i get "ch_date=2025-04-01" wich is what i chose in the page before submiting now i just need to know where to read it from inside of cmd.au3

Posted (edited)

Hi @JulianBejire :).

The request body will be passed into the script via stdin.

I do not have any example files for showing this currently, but i can try to make one later today or during the weekend.

Here is the lines that sends the body to the script from the request: https://github.com/genius257/AutoIt-HTTP-Server/blob/07ed9536ccef9498309747737c7a10c57c10440a/Server.au3#L474-L481

 

You can verify if the script was called with HTTP POST method via:

EnvGet("REQUEST_METHOD")

 

 

Edited by genius257
Posted

Thanks for the fast reply but that does not realy help me currently. The way i see it in other servers wich most of the time use php the request is send from an html form to an specific php script on the server and inside that php scrip you just read a global variable $_POST[keyname] wich is like an 2d array containing all key:data pairs send by the post request. I was hoping its similar here i send post to cmd.au3( in my case) and inside cmd.au3 i do something like $sRecived_Pair1data = $_POST[1] then based on the content of $sRecieved_Pair1data i do what i want spit out the response to the browser using ConsoleWrite("html of i want to be displayed "). I see the server script has global variables Global $aRequest, Global $aHeaders, Global $aUri that probably contain what i need but the scope of cmd.au3 that is called by the server.au3 cant see them.

So i will wait for the example of how to handle the post request if you find the time to make one that would be really helpful. 

Otherwise the server is great i read an sqllite3 database and display the resulting query data as nice html table in the browser. Works fast looks nice.

Posted

Newer mind my previous post it was helpful to know to look in stdin. i figured it out.

Inside the recieving cmd.au3 script of the post request i do in the beginning:

Local $sRecievedPostData = ConsoleRead()

And now my cmd.au3 has the users respons in the variable $sRecievedPostData as a string like this "ch_data=2025-01-01" wich is the key and data send by the html form in the index.au3.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...