api – PHPUnit – getallheaders不起作用
我正在测试我的代码,我的标题有问题.在每个api我使用
$headers = getallheaders(); 为了得到它,当我使用app或crhome postman扩展测试时,这工作正常. $client = $this->createClient(); $client->request('GET','/api/shotcard',['qrcode'=>'D0m1c173'],[],['HTTP_API_TOKEN' => 'abc123'] ); $this->assertEquals(200,$client->getResponse()->getStatusCode()); 我尝试用带有该测试令牌的用户拍摄带有该qrcode的卡(不是我将在应用程序中使用的令牌),我在这里看到这样的调用:https://stackoverflow.com/a/11681422/5475228.
从
this文章:
if (!function_exists('getallheaders')) { function getallheaders() { $headers = []; foreach ($_SERVER as $name => $value) { if (substr($name,5) == 'HTTP_') { $headers[str_replace(' ','-',ucwords(strtolower(str_replace('_',' ',substr($name,5)))))] = $value; } } return $headers; } } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |