5

I use the client-Object to simulate and test my Silex-Webservices. How can I send a JSON-Body with the PUT-method?

My idea was:

$crawler = $this->client->request('PUT', '/test', array(), array(), array(), '{"id":"34"}');

That does not work. :(

4

2 回答 2

10

请尝试使用此代码:

$client->request(
    'PUT', '/test', array(), array(),
    array(
        'CONTENT_TYPE' => 'application/json',
        'HTTP_X-Requested-With' => 'XMLHttpRequest'
    ),
    '{"id":"34"}'
);  
于 2013-03-11T02:38:36.990 回答
0

谢谢 Dimitry,不完全是我想要的,而是找到解决方案的一个很好的提示:

$client->request(
    'PUT', '/test', array(), array(),
    array(
        'CONTENT_TYPE' => 'application/json',
        'HTTP_X-Requested-With' => 'XMLHttpRequest'
    ),
   '{"id":"34"}'
);

您的解决方案有一个空数组,其想法是将 JSON 作为字符串传递!

非常感谢!干杯

于 2013-03-11T20:33:59.743 回答