POST路由不适用于laravel

时间:2015-04-06 17:00:42

标签: laravel post http-post

这是来自routes.php

的测试代码块
Route::post('testPost', function(){
    echo "Post received";
});

当我用POST请求命中时,我得到500内部服务器错误,但如果我更改第一行,那么它处理获取请求,如:

Route::get('testPost', function(){
...
一切正常。

这是我的.htaccess文件:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options +FollowSymLinks
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

有没有人知道什么是解决方案?

1 个答案:

答案 0 :(得分:0)

可能是您没有正确访问该网址。我的意思是/ testPost路径只接收post请求。你告诉过你用POST请求命中它,但你是怎么做到的?你做得好吗?你是否使用post方法使用表单提交或者使用任何REST客户端(例如邮递员)来发布请求?

总结一下,你的代码是绝对正确的,它应该适用于发布请求。访问网址时可能会有一些错误。