php - Send array as json and read that data -


i encoding array json , sending curl other file:

$data = array(   "authorizedkey" => "abbad35c5c01-xxxx-xxx",   "senderemail" => "myemail@yahoo.com",   "recipientemail" => "jaketalledo86@yahoo.com",   "comment" => "invitation",   "forcedebitcard" => "false" );  $data = json_encode($data);  $ch = curl_init('http://localhost/curl/1.php'); $headers = array('accept: application/json','content-type: application/json');   curl_setopt($ch, curlopt_customrequest, "post");   curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch, curlopt_postfields, $data); curl_setopt($ch, curlopt_followlocation, 1);  curl_setopt($ch, curlopt_httpheader, $headers);  echo curl_exec($ch); curl_close($ch); 

problem http://localhost/curl/1.php dont recieve $_post , dont know how operate on posted data.

http://localhost/curl/1.php output:

headers:   host = localhost   accept = application/json   content-type = application/json   content-length = 166 get:  empty post:  empty 

you sending data using request body, , supposed data request body not $_post super global. can use following code whole data.

$entitybody = file_get_contents('php://input'); 

Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -