I'm trying to write a custom web interface for my wifi pineapple nano. I am not an experienced coder or anything, but I know and somewhat understand php and decided to use php curl to talk to the build in REST API on the pineapple.
I've written the following code:
print "your code started</br>";
//define and encode json
/*$a = new \stdClass();
'message'=>'Hello from apache!',
$JSON = json_encode($a);
//curl post request
$c = curl_init();
curl_setopt($c, CURLOPT_CUSTOMREQUEST, "POST");
//curl_setopt($c, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($c, CURLOPT_RETURNTRANSFER, true);
curl_setopt($c, CURLOPT_URL, "172.16.42.1/api");
curl_setopt($c, CURLOPT_POST, true);
curl_setopt($c, CURLOPT_POSTFIELDS, $JSON);
curl_setopt($c, CURLOPT_HTTPHEADER, array(
'Authorization: ' . $key
//print curl output
$result = curl_exec($c);
$info = curl_getinfo($c);
die('Error: "' . curl_error($c) . '" - Code: ' . curl_errno($c));
//close curl request
print "</br>Your code ran";
On execution I get the following output:
your code started
200Error: "" - Code: 0
However, on the pineapple there's nothing happening. When I look at the data through wireshark, I get a lot of ' 301 moved permanently' packages.
Anyone know the answer to this, or maybe a better way of doing what I am trying to do?
Thanks in advance!
FYI: The curl request works in both CLI and postman, there doesn't seem to be any problem using these methods.