开发者

Posting XML to Rails

开发者 https://www.devze.com 2023-01-12 03:41 出处:网络
I am trying to 1) post some XML to my Rails App (without using forms) 2) have my Rail开发者_如何学运维s App then parse the posted XML to create entries within my database

I am trying to 1) post some XML to my Rails App (without using forms) 2) have my Rail开发者_如何学运维s App then parse the posted XML to create entries within my database

For example, I'd like to post

<transaction>
  <date>12-01-2010</date>
  <amount>1.00</amount>
</transaction> 
<transaction>
  <date>12-02-2010</date>
  <amount>2.00</amount>
</transaction>

Assuming I have a transaction controller. I'd then like to create an "upload" action that would allow me to parse the snippet above and create entries within my database.

From my research it seems like 1) can be accomplished with curl. But I'm not sure if that is right, because I don't know what URI to point the curl command to.

I am also not clear how to get the XML data within the "upload" action of my controller.

Any help would be appreciated.

Thank you!


You have to set Header Content-type, send as POST request and then you have only worry about the XML posted content


Here is a example of how to post xml by using curl

curl -X POST -H "Content-Type:text/xml" -d "<xml>Your XML Data</xml>" "http://your url"

XML parameter parser is removed in Rails 4, so if you're using Rails 4, you need to install actionpack-xml-parser gem first, refer to https://github.com/rails/actionpack-xml_parser

0

精彩评论

暂无评论...
验证码 换一张
取 消