Issue I'm having is it appears that GET is being sent with file_get_contents in my execute function below. For the life of me I cannot figure out why. I have tested the api server with Postman using POST and it works correctly.
The first function is used to pass in my requests to get sent to the server. The second function is in my form_handler.php file where it builds the data to send via execute() to the server.
api_handler.php
<?php
function execute($command, $context = NULL)
{
$url_scheme = "http://";
if (isset($_SERVER['HTTPS']))
{
$url_scheme = "https://";
}
$url_host = $_SERVER['HTTP_HOST'];
$url_api = "/SkedApi/";
$url = $url_scheme.$url_host.$url_api.$command;
echo $url . "<br/>";
var_dump($context);
var_dump(headers_list());
$response = file_get_contents($url, false, $context);
var_dump(headers_list());
echo $response;
if ($response)
{
$output = json_decode($response, true);
}
else
{
$output = "error";
}
return $output;
}
?>
users_handler.php
$test = array ('foo' => 'bar', 'bar' => 'baz');
$postdata = http_build_query($test);
echo $postdata;
$opts = array (
'http' => array (
'method' => 'POST',
'header'=> "Content-type: application/x-www-form-urlencoded\r\n"
. "Content-Length: " . strlen($postdata) . "\r\n",
'content' => $postdata
));
var_dump($opts);
$context = stream_context_create($opts);
print_r($context);
$result = execute("Users", $context);
if ($result)
{
echo "YES</br>";
}
From my apache access files:
::1 - - [04/Jul/2017:16:02:00 -0400] "POST /SkedApi/Users HTTP/1.0" 301 239
::1 - - [04/Jul/2017:16:02:00 -0400] "GET /SkedApi/Users/ HTTP/1.0" 200 196
::1 - - [04/Jul/2017:16:02:00 -0400] "POST /SkedAvailability/users_handler.php HTTP/1.1" 200 2688
Disclaimer: sorry about all the var_dumps;