send.php
Код: Выделить всё
$url = (empty($_SERVER['HTTPS']) ? 'http' : 'https') . "://".$_SERVER['HTTP_HOST'].str_replace(realpath($_SERVER['DOCUMENT_ROOT']), '', realpath(__DIR__))."/receive.php";
$data = array(
'first_name' => "Bart",
'last_name' => "Simpson",
);
$return_data=json_encode($data);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json', 'Content-Type: application/json'));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FAILONERROR, true); // Required for HTTP error codes to be reported via our call to curl_error($ch)
curl_setopt($ch, CURLOPT_POSTFIELDS, $return_data);
$resp = curl_exec($ch);
if (curl_errno($ch)) {
$ch_error_msg = curl_error($ch);
echo "ERROR:".$ch_error_msg;
exit;
}
curl_close($ch);
$result = json_decode($resp);
echo "
".var_export($result,true)."";
Код: Выделить всё
$response = file_get_contents('php://input');
$data = json_decode($response, true);
$data_display = var_export($data, true); // Nice readable view of array
if (isset($data['first_name']) && $data['first_name']!="")
{
http_response_code(200);
header("Content-Type:application/json");
$return_data["http_status_code"]="200";
$return_data["http_status_desc"]="OK";
echo json_encode($return_data);
exit;
}
else
{
http_response_code(400);
header("Content-Type:application/json");
$return_data["http_status_code"]="400";
$return_data["http_status_desc"]="Required data not supplied";
echo json_encode($return_data);
exit;
}
curl_setopt_array($ch,array(CURLOPT_VERBOSE=>1,CURLOPT_STDERR=>$stderrh));
$result=curl_exec($ch);
/* https://bugs.php.net/bug.php?id=76268 */
rewind($stderrh);
$stderr=stream_get_contents($stderrh);
fclose($stderrh);
echo "".$stderr."";
< /code>
до $ resp = curl_exec ($ ch); < /code> и теперь я вижу это дополнительное сообщение ... < /p>
process_pending_input: nghttp2_session_mem_recv () returned -902:
function function < /p> blect ().>
Подробнее здесь: https://stackoverflow.com/questions/793 ... -json-data