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. :(
请尝试使用此代码:
$client->request(
'PUT', '/test', array(), array(),
array(
'CONTENT_TYPE' => 'application/json',
'HTTP_X-Requested-With' => 'XMLHttpRequest'
),
'{"id":"34"}'
);
谢谢 Dimitry,不完全是我想要的,而是找到解决方案的一个很好的提示:
$client->request(
'PUT', '/test', array(), array(),
array(
'CONTENT_TYPE' => 'application/json',
'HTTP_X-Requested-With' => 'XMLHttpRequest'
),
'{"id":"34"}'
);
您的解决方案有一个空数组,其想法是将 JSON 作为字符串传递!
非常感谢!干杯