나는이 컬 a를 REST API에 JSON을 보내는 기능을 가지고 : 서버에서PHP REST API를 통해 JSON을 검색
$url = "https://server.com/api.php";
$fields = array("method" => "mymethod", "email" => "myemail");
$result = sendTrigger($url, $fields);
function sendTrigger($url, $fields){
$fields = json_encode($fields);
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json; charset=UTF-8"));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$curlResult["msg"] = curl_exec($ch);
$curlResult["http"] = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
return $curlResult;
}
을, 내가 가진 코드 :
$data = json_decode($_REQUEST);
var_dump($data);
exit();
나는 컬을 실행 명령을 내게 돌려 준다.
Warning: json_decode() expects parameter 1 to be string, array given in
그것은 어떠냐?
감사합니다.
은''json_decode'와 json_encode'을 혼합? – Brian
[PHP에서 POST의 본문을 얻는 방법] 가능한 복제본? (http://stackoverflow.com/questions/8945879/how-to-get-body-of-a-post-in-php) – Quentin
왜냐하면' $ _REQUEST'는 비어있는 경우라도 대부분 항상 배열입니다. JSON blob은 거기에 나타나지 않지만'php : // input'입니다. – mario