Reputation: 870
this is my code. and i am posting my data using post method.
$post_body = file_get_contents('php://input');
if(getenv('REQUEST_METHOD') == 'POST'){
print_r( array( "3","3d"));
}
print_r($post_body);
i am using chrome's postman to test this code,but it don't print post data, see output image.
what i am doing wrong???
EDIT
To show how i solve my problem i am adding this image.
Upvotes: 3
Views: 8287
Reputation: 1
The exact problem I experienced was fixed when I switched to the https protocol rather than http in the URL. For Example - http://example.com/test-api TO https://example.com/test-api
Upvotes: 0
Reputation: 165
I had the same problem. I was using api.example.fr/api.php
instead of https://api.example.fr/api.php
. Try to use the full link of your api.
Upvotes: 0
Reputation: 180
I had similar trouble testing symfony endpoint but with completely different cause:
My class had only functions in it. And i did a
var_dump(file_get_contents('php://input'));
on the first line of my function, which happens to be the first function in the class. This was returning empty("") even if parameters were correct.
My problem was that i forgot to use the FULL route to this, but since postman tried to run this function anyway got me too much time to notice. Hope it helps!
Upvotes: 2
Reputation: 21502
According to PHP documentation
php://input
is not available with enctype="multipart/form-data".
Postman supports different types of Content-Type
including multipart/form-data
which seems to be default.
So make sure you don't use multipart/form-data
(in the Body
tab).
Upvotes: 5