# POSTing XML - how do I test that?

**URL:** <https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917>\
**Category:** Rails\
**Created:** [February 26, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917 "2007-02-26T22:04:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 26, 2007, 10:04pm UTC](https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917/1 "2007-02-26T22:04:04Z")

</div>

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 [RailsNotes — The Ruby on Rails guides you wished you had.](http://www.railsweenie.com/forums/2/topics/709?page=6) ? Finally,  
how can I test this with curl? I’ve tried doing stuff like:

curl -d “foo”  
[http://localhost:3001/videos.xml](http://localhost:3001/videos.xml)

but that doesn’t work. The request params show  
“foo”=\>“”. 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

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 26, 2007, 10:58pm UTC](https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917/2 "2007-02-26T22:58:16Z")

</div>

On 2/26/07, Pat M. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 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 “Mission:  
Impossible” [http://localhost:3000/videos](http://localhost:3000/videos)

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

> **[eli.st](http://evang.eli.st/blog/2007/2/26/posting-xml-to-your-restful-controller)**
>
> This domain may be for sale!

Pat

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 26, 2007, 11:29pm UTC](https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917/3 "2007-02-26T23:29:22Z")

</div>

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:  
[http://snippets.dzone.com/posts/show/3521](http://snippets.dzone.com/posts/show/3521)

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)?  
ed

---

<div class="post-metadata">

**Author:** ![pergesu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/22d042/32.png) [@pergesu](https://www.ruby-forum.com/u/pergesu)\
**Post date:** [February 26, 2007, 11:55pm UTC](https://www.ruby-forum.com/t/posting-xml-how-do-i-test-that/86917/4 "2007-02-26T23:55:28Z")

</div>

On 2/26/07, Ed Hickey [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> command line (on your dev setup)?ed  
> 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.

Pat
