3

I'm writing some functional tests for a POST API endpoint. I've reviewed the documentation and can't find a way to add content to the POST body. The post method for sfBrowser:

post('some url',array('x'=>'y'))

Only creates POST parameters (in this case x=y). Is there anyway of adding content to the post body using sfBrowser?

Simon Cast
  • 255
  • 1
  • 9

1 Answers1

0

From what I have found here, here and here, the POST format takes parameter:value format, so you can send your JSON with some code like:

post('some url', array('json_data' => json_encode($toJson))

and then decode in your action with

$jsonObj = json_decode($request->getParameter('json_data'));

but you need to associate your JSON data with a parameter name in your POST to retrieve it on the server side.

As a side note, after looking at the Symfony code, the parameters are given straight to $_POST except for CSRF, which is tweaked.

Community
  • 1
  • 1
jaudette
  • 2,305
  • 1
  • 20
  • 20
  • 1
    I have no trouble with decoding values passed in the POST parameter format. The problem is adding data to the body of a POST. I'm using Zapier and they send data as a POST body and not as a POST parameter. The key here is sending POST body via the sfBrowser POST method. Having looked at the underlying code I don't think it is at all possilbe without changing the sfBrowser code which is a bit beyond me at the moment. – Simon Cast Oct 15 '12 at 10:19