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. :(

2 Answers 2

10

Please try to use this code:

$client->request( 'PUT', '/test', array(), array(), array( 'CONTENT_TYPE' => 'application/json', 'HTTP_X-Requested-With' => 'XMLHttpRequest' ), '{"id":"34"}' ); 
Sign up to request clarification or add additional context in comments.

1 Comment

user1879408 I switch jsone_encode to simple string, now it fit your needs. Please, accept it if it worked for you.
0

Thanks Dimitry, not exactly what I was looking for, but a great hint to find the solution:

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

Your solution had one empty array to much and the idea was to pass in JSON as string!

Thanks a lot! Cheers

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.