0

I'm trying to create a POST API with Flightphp. I've wrote the following code:

 Flight::route('GET /addProduct', function(){
  echo "GET REQUEST";
 });
 Flight::route('POST /addProduct', function(){
  echo "POST REQUEST";
  var_dump($_POST);
 });

If I perform with Postman a POST request, the output is "GET REQUEST" (and no $_POST variable is printed).

How can I receive a POST request? Why I send a code and the server receives another one?

alessandro308
  • 1,912
  • 2
  • 15
  • 27
  • When you make the request, do you have a trailing `/`? Example: `/addProduct/`. Web servers can be set to redirect all requests with trailing slashes to non-trailing slashes. When the redirect is done, it will become a GET request. – M. Eriksson Apr 18 '18 at 07:11
  • Yes, also with the `/` retuns `GET REQUEST` – alessandro308 Apr 18 '18 at 07:12
  • The `.htaccess` is the following ```Options -Indexes RewriteBase /magazzino/db/api RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php [QSA,L]``` – alessandro308 Apr 18 '18 at 07:14
  • That's not handled by the htaccess but rather the web server settings. Are you using Apache? – M. Eriksson Apr 18 '18 at 07:16
  • I'm using "tophost.it", an italian hosting that use Apache – alessandro308 Apr 18 '18 at 07:16
  • I would contact them and explain your issue to see if there's something they've done. – M. Eriksson Apr 18 '18 at 07:17
  • your code working fine on my side, maybe the issue in your post man request? how do your perform the post request there? – hassan Apr 18 '18 at 07:17
  • Postman request: https://image.ibb.co/fRngsS/Schermata_2018_04_18_alle_09_18_27.png – alessandro308 Apr 18 '18 at 07:20

0 Answers0