由于某些原因,当我发送一个新的$client->请求我指定的标题丢失:
原文链接:https://www.f2er.com/php/140088.htmlpublic function testGetClientsAction() { $client = static::createClient(); $cookie = new Cookie('locale2','en',time() + 3600 * 24 * 7,'/',null,false,false); $client->getCookieJar()->set($cookie); // Visit user login page and login $crawler = $client->request('GET','/login'); $form = $crawler->selectButton('login')->form(); $crawler = $client->submit($form,array('_username' => 'greg','_password' => 'greg')); $client->request( 'GET','/clients',array(),array('X-Requested-With' => 'XMLHttpRequest','accept' => 'application/json') ); print_r($client->getResponse()); die();
}
在正在测试的方法中,我在第一行:
print_r($request->headers->all());
答复如下:
Array ( [host] => Array ( [0] => localhost ) [user-agent] => Array ( [0] => Symfony2 BrowserKit ) [accept] => Array ( [0] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 ) [accept-language] => Array ( [0] => en-us,en;q=0.5 ) [accept-charset] => Array ( [0] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 ) [referer] => Array ( [0] => http://localhost/login_check ) [x-PHP-ob-level] => Array ( [0] => 1 ) )