1

I have this simple code

<?php
$json = array("status" => $_POST['name']);
header('Content-type: application/json');
echo json_encode($json);
?>

and when i send POST data with Advanced REST cliend, allways have an empty $_POST table. enter image description here

guy_fawkes
  • 947
  • 8
  • 31
dios231
  • 714
  • 1
  • 9
  • 21

1 Answers1

2

You are using wrong transport method. If you want to read POST data in $_POST array you have to send it either as multipart or www form urlencoded.

To read the request body you have to use following code:

$postdata = file_get_contents("php://input");

Then you can parse the JSON and transform it to object.

If you want to read the data from the request using $_POST array you need to set Content-Type header to application/x-www-form-urlencoded and send the data as:

param-name=param+value

(note that it is url encoded).

Pawel Uchida-Psztyc
  • 3,735
  • 2
  • 20
  • 41