【问题标题】:laravel 5 token with angularjs带有angularjs的laravel 5令牌
【发布时间】:2015-06-02 07:29:50
【问题描述】:

AngularJs 正在工作

angular.module("myApp").run(function($http){
        $http.defaults.headers.common['mytoken'] = $('meta[name=csrf-token]').attr('content');
    })

中间件 Laravel 5

class BeforeCsrf implements Middleware {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {

        if (Session::token() !== (string)$request->header('mytoken')){
            prin_r($request->header('mytoken'));
        }

        return $next($request);
    }

}

但是$request->header('mytoken') 不起作用。

对不起,我的英语不好

【问题讨论】:

  • do inside run console.log($('meta[name=csrf-token]').attr('content')) 有什么价值吗
  • 我尝试console.log($('meta[name=csrf-token]').attr('content')) 使用令牌字符串,并检查console.log($http.defaults.headers.common['mytoken']) 具有相同的值

标签: php angularjs token csrf laravel-5


【解决方案1】:

prin_r($request->header('mytoken'));

你写的是 prin_r 而不是 print_r 可能你遇到了一个错误,而你的服务器正在向你隐藏错误。

【讨论】:

    猜你喜欢
    • 2017-12-12
    • 2017-03-10
    • 2015-05-19
    • 2015-06-02
    • 2018-09-22
    • 2015-02-08
    • 2018-05-19
    • 2019-06-29
    • 1970-01-01
    相关资源
    最近更新 更多