POSTing XML - how do I test that?

If I use map.resources, Rails should automatically pull the parameters out of the XML for me, right? Or do I have to do a slurp_params trick like ? Finally, how can I test this with curl? I've tried doing stuff like:

curl -d "<video><title>foo</title></video>" http://localhost:3001/videos.xml

but that doesn't work. The request params show "<video><title>foo</title></video>"=>"". That's without using slurp_params...and when I do that, the format is url_encoded instead of xml.

So two questions. 1. Do I need to do anything special to parse XML params? 2. How can I test POSTing XML to my controller?

Thanks, Pat

Turns out Rails does everything automatically if you set the X-POST_DATA_FORMAT header.

curl -H "X-POST_DATA_FORMAT: xml" -d "<video><title>Mission: Impossible</title></video>" http://localhost:3000/videos

Short blog post if anyone wants an easy link to share:


I’m running rails 1.2.2 and don’t have to pass the X_POST_DATA_FORMAT header to get Rails to read my XML string. This is the test script I use:

It basically just sets the Accept and Content-Type headers and then puts the XML text.

Are you running these curl calls from your functional tests or from the command line (on your dev setup)?


I was just running it from the command line. I just did some testing, and setting Content-Type to application/xml is all that's needed apparently. Thanks.