PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, January 16, 2022

[FIXED] Symfony2 app.php receiving POST request as GET app_dev.php works fine

 January 16, 2022     get, php, post, postman, symfony     No comments   

Issue

So I'm creating a route that requires posting. The route is as follows:

my_route:
  path:     /myroute/login
  defaults: { _controller: "MyBundle:Default:login"}
  methods:  [POST]

So I use postman to hit app_dev.php/myroute/login and I get the correct response that I am looking for, currently the page just returns "hello world". Now when I change postman to just hit app.php/myroute/login I get an error saying:

The server returned a "405 Method Not Allowed".

I'm really confused as to why it says method not allowed so I tailed the prod.log file and got the following:

Uncaught PHP Exception Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException: "No route found for "GET /myroute/login": Method Not Allowed (Allow: POST)"

I'm sending the requests in postman as POST requests but somehow symfony is only seeing them as GET requests. Again I can change the url to app_dev.php/myroute/login and hit send and it works. I thought it was a caching issue so I tried the following to clear the caches:

$ php app/console cache:clear --env=prod --no-debug

This still doesn't clear my problem so I even removed all the files from app/cache/prod as well. I can't find anyone having issues that are similar to this so I'm hoping someone can point me in the right direction. I also thought it might be


Solution

After some more digging I discovered what the issue was. So I thought that maybe it was postman that was sending the incorrect method so I googled around for that which lead to this

Postman sending POST as GET

which lead to a question about htaccess files:

Redirect POST htaccess

So first off I set postman to hit app.php/myroute/login and xdebug showed the request method as GET. I moved the .htaccess file and hit the same url and the request method showed up as POST. Instead of hitting that url I moved my .htaccess file back and pointed at just /myroute/login and everything lit up. This was an extremely annoying exercise so I hope that this will save someone else in the future looking for the same problem.



Answered By - Cody
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing