This is a read-only snapshot of the ComputerCraft forums,
taken in April 2020.
How to use HTML api (What code to put the web site)
Started by Magic_RB, 09 January 2015 - 07:30 PMPosted 09 January 2015 - 08:30 PM
So i can't completly understand how does the api itself work a also i can't get to work the other side (the site code). I know that i'm asking about html but this is the best place to get answer. Isn't it? Thank you.
Posted 09 January 2015 - 11:17 PM
If you are taking about http, you can't/shouldn't use html. http.get returns the raw source code of the webpage.
Take, for example, pastebin. The url the pastebin get command uses is something like this: http://pastebin.com/raw.php?i=3eMtT5vX.
You can, however, use PHP and http.post to "communicate" between a site and an in game script.
Take, for example, pastebin. The url the pastebin get command uses is something like this: http://pastebin.com/raw.php?i=3eMtT5vX.
You can, however, use PHP and http.post to "communicate" between a site and an in game script.
Posted 10 January 2015 - 04:10 AM
Bear in mind the wiki has examples for each of the http API's functions: http://www.computercraft.info/wiki/HTTP_%28API%29
Posted 10 January 2015 - 12:04 PM
http sorry :D/>
thx i will try it out.
ok so i have installed php but what code do i have to use to retrieve the posted data?
found out see this: http://www.computerc...s-on-a-website/
I can't get http.get to work. Every time i try to get it working i get the same error.
g:2: attempt to index ? (a nil value)
This is the code.
thx i will try it out.
ok so i have installed php but what code do i have to use to retrieve the posted data?
found out see this: http://www.computerc...s-on-a-website/
I can't get http.get to work. Every time i try to get it working i get the same error.
g:2: attempt to index ? (a nil value)
This is the code.
data = http.get("www.google.com")
print(data.readAll())
data.close()
:)/>Edited on 10 January 2015 - 07:46 PM
Posted 10 January 2015 - 08:47 PM
Threads merged. Please stick to one topic for all questions about a single piece of code/project.
Posted 10 January 2015 - 09:24 PM
In ComputerCraft's config file, make sure the domain is accessible by the http API. By default, most aren't.
Posted 10 January 2015 - 09:37 PM
Don't you have to include the http:// part? I've seen it in every working http call.
Try "http://www.google.com" or "https://www.google.com"
Try "http://www.google.com" or "https://www.google.com"
Posted 10 January 2015 - 10:38 PM
I dunno, but I'd hope not, given that all that's there for is to specify the protocol - which, if you're using the http API, is already a given.
Posted 11 January 2015 - 01:43 AM
Yes, AFAIK "http://" part is required.
Please note that HTTP API returns Nil when request fails (and throws "http_failure" event) - That's why You are getting "attempt to index ?" exception. Also, google may not be the best website to use for testing - it is rather picky about all data sent within HTTP requests.
Please note that HTTP API returns Nil when request fails (and throws "http_failure" event) - That's why You are getting "attempt to index ?" exception. Also, google may not be the best website to use for testing - it is rather picky about all data sent within HTTP requests.