dongxiaofa6359 2019-05-15 11:25
浏览 51

“如何修复'尝试获取非对象的属性'标题'”VerifyCsrfToken

I run my project and i get this error:

Trying to get property 'headers' of non-object in "\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php"

in this function

    protected function addCookieToResponse($request, $response)
    {
        $config = config('session');

        $response->headers->setCookie(
            new Cookie(
                'XSRF-TOKEN', $request->session()->token(), $this->availableAt(60 * $config['lifetime']),
                $config['path'], $config['domain'], $config['secure'], false, false, $config['same_site'] ?? null
            )
        );

        return $response;
    }
  • 写回答

1条回答 默认 最新

  • dongyouji7022 2019-05-15 11:36
    关注

    What are you actually passing as $response argument in this case?

    I believe one needs more details to come up with the concrete cause of why you are getting the error, however I can try to give a hint:

    For some reason what you pass in place of $response is not being recognized as an instance of an object in your case. You could try instantiating it like so:

    $response = Response::make($contents, $statusCode);
    
    $response->header('Content-Type', $value);
    

    and then pass it to your function.

    Maybe you can try and trace back based on this assumption, where exactly in your Project the chain is broken?

    I mean, in your case it is a parameter in your function, but how would it know that it inherits from the Symfony\Component\HttpFoundation\Response class?

    Maybe you should "typehint" it -> like say Response $response in the brackets.

    I found this link here to be useful explanation also. In the post they talk about Request and not Response, but I think the principle of the issue is is related:

    https://www.quora.com/What-does-Request-request-mean-in-Laravel

    You can check out the documentation:

    https://laravel.com/docs/4.2/responses

    评论

报告相同问题?

悬赏问题

  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)