Files
votianng/html/tools/test_ca.php
2026-03-29 10:34:57 +02:00

57 lines
1.4 KiB
PHP

<?php
//include_once("../include/dbglobal.inc.php");
////phpinfo(); die();
//
//$sqlquery = "SELECT * FROM metatype WHERE mt_type = 'vehicletype'";
//$res = $db->query($sqlquery);
//if (DB::isError($res))
// reportDie ("$PHP_SELF: '$sqlquery' : " . $res->getMessage());
//while ($row = $res->fetch_assoc()):
// print_r($row);
//endwhile;
$postArray = array(
"stations" => array("Schwarzenbek", "Lauenburg"),
"hq_id" => 2,
"jb_id" => 12
);
//{
// "stations": [
// "Schwarzenbek",
// "Lauenburg"
// ],
// "hq_id": 2,
// "jb_id": 12
//}
print_r(sendHttpPostJson("http://172.16.0.158:81/api/pzm", $postArray));
function sendHttpPostJson ($url, $postArray = array()) {
$jsonData = json_encode($postArray);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
$json_response = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($status != 201) {
die("Error: call to URL $url failed with status $status, response $json_response, curl_error " . curl_error($curl) . ", curl_errno " . curl_errno($curl));
}
curl_close($ch);
return json_decode($json_response, true);
}
?>