I have a small script on my server to catch a POST request, like this:
<?php
$jsonformat = json_encode($_POST);
$jsonFile = fopen("data.json", "w") or die("Unable to open file!");
fwrite($jsonFile, $jsonformat);
fclose($jsonFile);
echo "success";
?>
Above script is named index.php and placed in http://example.com/data/report/
I have another script for sending the POST request like this:
<?php
$url = 'http://example.com/data/report/';
$data = array('key1' => 'value1', 'key2' => 'value2');
$options = array(
'http' => array(
'header' => "Content-type: application/x-www-form-urlencoded\r\n",
'method' => 'POST',
'content' => http_build_query($data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
var_dump($result);
?>
The two script are working great. But in another situation the $url is like this: 'http://example.com/data/report' Notice no "/" at the end of the url. In the situation without "/" at the end the json-file on server is still generated but it is empty.
I have no possibility adding the "/" to the url. Its a device where I can not edit the code but I know it is missing "/" at the end so code above is just my example. I have reproduced the issue, I think.
So my question is: - Why is it working with "/" but not without? - Can I do anything on the server so http://example.com/data/report will be the same as http://example.com/data/report/
I have access to .htaccess on the server