2012-02-22 16 views

cevap

32

"Sorunlu" cevap aramadan sonra doğru sözdizimi şöyledir: POST için

$crawler = $client->request('GET', '/foo/', array(), array(), array(
    'HTTP_X-Requested-With' => 'XMLHttpRequest', 
)); 
6

Request#isXmlHttpRequest() yöntemi, X-Requested-With başlığının XMLHttpRequest eşdeğerine denk olup olmadığını denetler. size bir istek ajax çağrı olup olmadığını belirlemek için kullandığınız yöntem ise, o zaman isteğine ilgili başlığı ekleyerek Test istemci davranışını simüle edebilirsiniz:

class FooFunctionalTest extends WebTestCase 
{ 
    $client = static::CreateClient(); 
    $crawler = $client->request('GET', '/foo/', array(), array(), array(
     'X-Requested-With' => 'XMLHttpRequest', 
    )); 
    // ... 
} 

fazla bilgi hakkında bulunabilir İstek nesnesi in the source code.

+0

Test ettikten sonra çalışmıyor. :/ – bux

+0

sözdizimi sorunu, yanıtıma bakın. Teşekkürler =) – bux

2

, PUT:

$crawler = $client->request('POST', '/foo/', array(), array(), array(
    'HTTP_X-Requested-With' => 'XMLHttpRequest', 
    'CONTENT_TYPE' => 'application/json', 
), '{"param": "value"}'); 
:

$crawler = $client->request('POST', '/foo/', array('param' => 'value'), array(), 
array(
    'HTTP_X-Requested-With' => 'XMLHttpRequest', 
)); 

çiğ JSON gövdeli POST, PUT için

İlgili konular