Noob - Can't get POST to work

I wrote the following php code

<?php use \Psr\Http\Message\ServerRequestInterface as Request; use \Psr\Http\Message\ResponseInterface as Response; require '../vendor/autoload.php'; $app = new \Slim\App; $app->post('/TestService', function (Request $request, Response $response) { $data = $request->getParsedBody(); $response->getBody()->write($data['name']); return $response; }); $app->run(); Then I send post data like this /usr/bin/curl -H "Content-Type: application/json" -X POST -d '{"name":"demo"}' http://172.16.27.190:5500/TestService and I get a 404 error. I can run the GET example fine from this exact location on the file system, so I am assuming this is an issue with my SLIM code

If you look in your server’s access log, what URL does it say you are hitting when you get the 404?

php -S 172.16.27.190:5500
PHP 7.0.15-0ubuntu0.16.04.4 Development Server started at Wed Mar 8 16:22:08 2017
Listening on “http://172.16.27.190:5500” (I put this in quotes so it could post to the thread)
Document root is /home/joelparker/src/public
Press Ctrl-C to quit.
[Thu Mar 9 05:26:48 2017] 172.16.27.190:34096 [404]: /TestService

Oh, didn’t realize you were using the built in PHP server… not sure if it has access log capabilities. I was hoping to have it show the URL being accessed.

I’m headed out for the day so I won’t be able to try your code until tomorrow, perhaps someone else can see the issue right away or give the code a try.

I’m embarrassed to say that it was a typo, all working now.

1 Like

Hey, no worries… we’ve all done that!