DEV Community

Discussion on: Catch and parse JSON Post data in PHP

Collapse
 
aitorxs profile image
jose machuca

Hello! I am trying to send a json in the following way

$factura ->acciones = array('enviar_xml_firmado' => false );

$ch = curl_init($url);
$jsonDataEncoded = json_encode($factura);

curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , $authorization ));
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$jsonDataEncoded);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$result = curl_exec($ch);
curl_close($ch);
return json_decode($result);

but I get the error $HTTP_RAW_POST_DATA de php 5.6, in which part or in what form should I go
$data = json_decode( file_get_contents( 'php://input' ), true );

so that it works well?

Collapse
 
dev_nope profile image
Vasile Stefirta πŸ‡²πŸ‡© ✈️ πŸ‡ΊπŸ‡Έ

Hi there, were you able to solve the issue?