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,735
  • 4
  • 26
  • 36
Aditya Banerjee
  • 161
  • 1
  • 4
  • 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
  • 11,506
  • 16
  • 62
  • 109
Josef Adamcik
  • 5,620
  • 3
  • 36
  • 42
0

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

<?php

$data_back = $_POST;

return $data_back;

?>
Sim1-81
  • 618
  • 4
  • 14