Server: (POST.php)
<?php
header('Content-Type:text/plain; charset=utf-8');
echo json_encode($_POST);
Client:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
header('Content-Type:text/plain');
$data['foo']='bar';
if (function_exists('curl_init')) {
$ch = curl_init('https://192.168.1.251/Tests/POST.php');
if ($ch) {
### curl_setopt($ch, CURLOPT_URL, $this->url);
### Hä? Wozu? Schmeisst einen Fehler! Mach das weg!
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
$ret = curl_exec($ch);
if ($ret) {
echo "Antwort:\n\n";
print_r($ret);
} else {
echo 'Curl-Fehler: ' . curl_error($ch) . "\n";
}
} else {
echo "Curl wurde nicht initialisiert.\n";
}
} else {
echo "Curl ist nicht installiert.\n";
}
Abruf des Client-Skriptes im Browser:
Antwort:
{"foo":"bar"}
Geht also. Allerdings musste ich erst
sudo apt-get install php-curl
und dann noch
sudo service apache2 restart
ausführen. Weil php-curl (Ich hab php 7 auf dem Testsystem) nicht installiert war bzw. das Modul nicht automatisch aktiviert wurde.