This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Rooon's profile picture

[Question] Make a website respond to a http.post()

Started by Rooon, 08 July 2012 - 07:54 PM
Rooon #1
Posted 08 July 2012 - 09:54 PM
How do i make a website respond to a http.post sent by a program in computercraft?
I know that you use:

http.post("http://site.com", variables)
But how do i read these variables for example in an PHP file?

Thanks in advance! :)/>/>
KevinW1998 #2
Posted 08 July 2012 - 09:57 PM
You should look more in an PHP-Forum than a lua-Forum!
Or is there any problems with http.post()?
Rooon #3
Posted 08 July 2012 - 10:01 PM
You should look more in an PHP-Forum than a lua-Forum!
Or is there any problems with http.post()?
No problems, i only want to know what http.post("link","this") does and how i can read and respond to it from my site.
xuma202 #4
Posted 08 July 2012 - 10:14 PM
the php script can read out the post variables easily. Use the array $_POST
Rooon #5
Posted 08 July 2012 - 10:28 PM
the php script can read out the post variables easily. Use the array $_POST
Thanks i'll try that!
Rooon #6
Posted 09 July 2012 - 01:31 AM
the php script can read out the post variables easily. Use the array $_POST
Thanks i'll try that!
It works perfectly!
Only one more thing though, how do i respond with a code that has been generated for uploading the file?
i tried

return $key;
but that just responds with a blank value..
xuma202 #7
Posted 09 July 2012 - 10:06 AM
I guess that http.post returns that, what you would get when you view the source code of the website that get's generated when you visit the php-file with the same parameters (POST variables) via your webbrowser.

So your php code can return stuff using the function print("TEST") or the function echo("TEST") or simply echo "TEST"
Of course you can replace the "TEST" with your variables or concatenate them with others or a string ("TEST: "..$var)

Try getting a bit familiar with PHP if you want to use if-then-else constructions or for-/while-loops …