I'm reworking my Learn With Book series on Angular, and ran into an issue running the new PHP login code from Postman.

The REST service is, generically, like this:

view plain print about
1header("Content-Type: application/json; charset=UTF-8");
2header("Access-Control-Allow-Methods: POST");
3
4$method = $_SERVER['REQUEST_METHOD'];
5
6switch ($method) {
7 case 'POST':
8 // do stuff
9
10 break;
11 default:
12 http_response_code(404);
13 break;
14}

No matter what my settings were in Postman, the $method was always showing a GET request instead of a POST request, and as such a 404 error was always returned instead of running my code.

The problem? I had removed the trailing slash. I was trying to load this:

view plain print about
1http://localphp.angular.learn-with.com/api/user/login

And that was performing some type of server side redirect, which was changing the request type from POST to GET.

But, once I add back in the trailing slash:

view plain print about
1http://localphp.angular.learn-with.com/api/user/login/

Then the REQUEST_METHOD was properly being seen by the PHP code, and my code ran as expected.

I have WampServer running locally for development, which I believe uses Apache under the hood, so perhaps this is some type of Apache Configuration issue.

Not surprisingly, this slash caused an issue with my Angular Proxy. I'll talk about that next week.