justRadojko's avatar

Route doesn't work for POST method

Hi,

Here is relevant chunk of code from routes.php

Route::post('testPost', function(){
    echo "Post received";
});

When I hit it with POST request using hurl.it I get 500 Internal server error, but if I change first line so it handles get requests like:

Route::get('testPost', function(){
...

everything works fine.

My .htaccess file is as default.

Does anyone have an idea what can be the solution?

EDIT:

I've was modifying .htaccess file and now I'm getting TokenMismatchException.

0 likes
2 replies
timetraveller1992's avatar

I disabled CSRF tokens and it still didn't work. When I copied the app to my local machine it worked fine but not on the server. After digging further I realized that all my requests DELETE, HEAD, PUT, POST were seen as GET by the server. I did a:

cd myproject/public
mv index.php index.bak
touch index.php

And wrote:

<?php
echo $_SERVER['REQUEST_METHOD'];

and tested the code on my machine and the server by making a POSTMAN Post Call. The server kept returning GET. After digging further I found that the apache2 server was misconfigured. Whoever did the devops to set up the server screwed up bigtime since the apache2 was taking all requests as GET. I think it might be because he setup https to redirect but at this point I'm not sure where he screwed it up.

1 like

Please or to participate in this conversation.