简体   繁体   中英

Not getting post value from file_get_contents('php://input')

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.

  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.

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

<?php

$data_back = $_POST;

return $data_back;

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM