0

I am having an issue when I am using a post request on an PHP file and I am passing simple keys and values to post. For example say key = productId and value = 123.

<?php

$data_back = json_decode(file_get_contents('php://input'));

return $data_back;

I am receiving nothing. Please assist.

agrm
  • 3,437
  • 4
  • 24
  • 34
Aditya Banerjee
  • 151
  • 1
  • 3
  • 18

2 Answers2

1
  1. Check how is your request created. It must be POST and php://input is not available for enctype="multipart/form-data"

  2. Problem may be json_encode() receiving invalid JSON. Check for json_decode error and/or check if the output from file_get_contents('php://input') is really empty.

Ari Seyhun
  • 10,213
  • 15
  • 54
  • 98
Josef Adamcik
  • 5,392
  • 3
  • 34
  • 42
0

in PHP file you can catch post request variabile just using $_POST array.

<?php

$data_back = $_POST;

return $data_back;

?>
Sim1-81
  • 610
  • 4
  • 12