如何在Laravel测试中获取标头值 [英] How to get header values in laravel testing

查看:71
本文介绍了如何在Laravel测试中获取标头值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我如何在测试用例中获得答复的方式

This is how i get response in test Case

$response = $this->call('POST','/api/auth/login',['username'=>'xx','password'=>'xxx'], [/* cookies */], [/* files */], ['HTTP_ClientSecret' => 'xxxx']);

然后我们可以像这样获取响应内容

Then we can get response content by like this

$ response-> getContents()

我想知道如何获取响应头数据?

i want to know how to get response header data ?

推荐答案

执行类似操作:

$response->headers->get('content-type');

或您需要的任何内容.如果您想查看响应头中的内容, dd($ response-> headers); 可能对您很有用.

or whatever you need. Also dd($response->headers); might be useful to you if you want to see what is in your response headers.

$ this-> call()返回响应,它扩展了Symfony的响应 headers 是对象 ResponseHeaderBag ,它具有

$this->call() returns Response which is extending Symfony's Response and headers is an object ResponseHeaderBag which has the following methods.

这篇关于如何在Laravel测试中获取标头值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆