【问题标题】:Laravel get data from external post submit: TokenMismatchException ( without adding _token)Laravel 从外部帖子提交获取数据:TokenMismatchException(不添加 _token)
【发布时间】:2015-05-09 18:17:40
【问题描述】:

我有一个只能控制操作 URL 的表单。所以不能添加'_token'。是否可以将数据发送到我的控制器

引用位置的外部 HTML 表单宿主

<!DOCTYPE html>
<html>
<head>
    <title>Test HTML</title>
</head>
<body>
<form method="post" action="http://www.mylaravelproject.com/confirm">
    <input type="textbox" name="fname">
    <input type="textbox" name="lname">
    <input type="submit">
</form>
</body>
</html>

我的 Laravel 路线

Route::any('confirm','PageController@confirm');

内部控制器

public function confirm(){
return Input::all();
}

这可能吗??

谢谢

编辑:

发现我可以通过删除行来做到这一点(在 App/Httm/Kenel.php 内)

'App\Http\Middleware\VerifyCsrfToken',

第二个问题 但它的安全风险。我只需要删除这条特定路线上的 VerifyCsrfToken '确认'。

这可能吗?

【问题讨论】:

    标签: laravel laravel-5


    【解决方案1】:

    此功能将在 Laravel 5.1 中开箱即用。

    但是当我们等待 Laravel 5.1 时 - 你可以在 5.0 中的 App\Http\Middleware\VerifyCsrfToken 文件中执行此操作:

    <?php namespace App\Http\Middleware;
    
    use Closure;
    use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken as BaseVerifier;
    use Illuminate\Session\TokenMismatchException;
    
    class VerifyCsrfToken extends BaseVerifier {
    
        protected $excludedRouteGroups = ['confirm', 'stripe'];
    
    
        public function handle($request, Closure $next)
        {
            if ($this->isReading($request) || ($this->excludedRoutes($request)) || $this->tokensMatch($request)) {
                return $this->addCookieToResponse($request, $next($request));
            }
    
            Throw new TokenMismatchException;
        }
    
    
        protected function excludedRoutes($request)
        {
            foreach($this->excludedRouteGroups as $route) {
                if ($request->segment(1) === $route) {
                    return true;
                }
            }
    
            return false;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-07-17
      • 2014-04-15
      • 1970-01-01
      • 2014-09-20
      • 2020-09-15
      • 2014-04-03
      • 2017-12-06
      • 2015-01-16
      相关资源
      最近更新 更多