使用PHP发布JSON字符串并将其卷曲到PHP页面并获得响应

使用PHP发布JSON字符串并将其卷曲到PHP页面并获得响应,php,arrays,json,curl,Php,Arrays,Json,Curl,我试图学习如何通过CURL将一个PHP发布到另一个PHP页面并阅读响应 我有两页。第一个是test.php <?php $array['User'] = array(); $array['User']['AppId'] = 'sdfgfd9-sdfgsdf-sdfgfdgfgff'; $array['User']['UserName'] = 'me@example.co.uk'; $array['User']['Token'] = 'fsdgf5-455g-223ee-bggg-asdsa

我试图学习如何通过CURL将一个PHP发布到另一个PHP页面并阅读响应

我有两页。第一个是test.php

<?php
$array['User'] = array();
$array['User']['AppId'] = 'sdfgfd9-sdfgsdf-sdfgfdgfgff';
$array['User']['UserName'] = 'me@example.co.uk';
$array['User']['Token'] = 'fsdgf5-455g-223ee-bggg-asdsadsda';
$array['User']['Timestamp'] = '2018-05-30BST16:28:293600';

$url = "https://www.myurl.co.uk/api/index.php";    
$content = json_encode($array['User']);

$curl = curl_init($url);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER,
array("Content-type: application/json"));
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, $content);

$json_response = curl_exec($curl);

$status = curl_getinfo($curl, 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($curl);

$response = json_decode($json_response, true);
echo $response;
?>
我对错误的理解不够,无法理解如何更改以使其正常工作?

尝试: curl_setopt($curl,CURLOPT_HTTPHEADER, 排列( '方法'=>'发布', 'header'=>'内容类型:application/json'。“\r\n” .“内容长度:”.strlen($data\u string)。“\r\n”, 'content'=>$data\u字符串, ))


或者类似的

200不是错误代码,而是成功代码。请以200为成功代码重试,并报告结果。我没有意识到围绕输出的if语句不正确。这一切工作正常谢谢
<?php
$userArray = array();   
$userArray = trim(file_get_contents("php://input"));
echo json_decode($userArray, true);
?>
Error: call to URL https://www.myurl.co.uk/api/index.php failed with status 200, response Array, curl_error , curl_errno 0