Posted 24 November 2013 - 03:09 PM
This has probably been asked 100 times before. But since i searched these forums and the wiki and still can't figure it out. I'm sure this qualifies as a legitimate cry for help.
I've been messing with computercraft a while and absolutely love it. But right now i have a number of questions i can't seem to find the answer to. And they are basically all related to the HTTP API
I'm trying to setup some basic mysql connections, just for fun and messing around. But in order to get to that point i wanted to test out the HTTP functions first.
I run into the problem that i can't seem to verify if anything is actually happening. On the wiki it says the http.post() return a handle that i can use .readLine() on. This brings up a "Attempt to index ?" error on CC.
Does the http API still return a handle? How do i use it?
Since i am sending the http post to the same machine that has the server and php+mysql on it is there a way i can use "localhost" in the URL? Just "localhost" gives invalidURL error. Perhaps "http://localhost" ?
My current code looks like this:
Using the PHP code:
(I know the current code would be useless. This is how i bug test my own code.)
I've been messing with computercraft a while and absolutely love it. But right now i have a number of questions i can't seem to find the answer to. And they are basically all related to the HTTP API
I'm trying to setup some basic mysql connections, just for fun and messing around. But in order to get to that point i wanted to test out the HTTP functions first.
I run into the problem that i can't seem to verify if anything is actually happening. On the wiki it says the http.post() return a handle that i can use .readLine() on. This brings up a "Attempt to index ?" error on CC.
Does the http API still return a handle? How do i use it?
Since i am sending the http post to the same machine that has the server and php+mysql on it is there a way i can use "localhost" in the URL? Just "localhost" gives invalidURL error. Perhaps "http://localhost" ?
My current code looks like this:
local h = http.post("<url>","data1=bla&data2=bla&data3=bla")
repeat
local line = h.readLine()
print(line)
until not line
h.close
Using the PHP code:
<?php
if (isset($_POST['db']) && isset($_POST['usr']) && isset($_POST['pwd']){
$database = urldecode($_POST['db']);
$username = urldecode($_POST['usr']);
$password = urldecode($_POST['pwd']);
print "Provided information:<br />";
print "Connecting to: " . $database . "<br />";
print "Using data: " . $username . "/" . $password;
}
else {
print "Please provide Database, Username and Password.";
}
?>
(I know the current code would be useless. This is how i bug test my own code.)