如何接受POST XML到Rails控制器

时间:2015-01-29 19:54:18

标签: ruby-on-rails xml

我有一个网络服务,它将以POST的形式向我的网站发送XML我正试图找出如何实际接收XML数据。

这不是一个文件,它将是数据的POST请求

我可以设置一条路线发布到但是我怎样才能捕获信息并将其发送给nokogiri以便我可以解析它

发布网址

website.com/post_everywhere/create_account

路线:

resources :post_everywhere do
  post :create_account
end

控制器:

class PostEverywhereController < ApplicationController
  def create_account

    /**** How do i capture the info here ****/

  end
end

示例数据:

<PELoadPostings>
    <PostingAccount>
        <UserName></UserName>
        <Password></Password><!-- for post free without account, UserName and Password are not set -->
        <ContactName></ContactName>
        <ContactPhone></ContactPhone>
        <ContactFax></ContactFax>
        <ContactEmail></ContactEmail>
        <CompanyName></CompanyName>
        <UserID></UserID><!-- for posting with account ContactName, ContactPhone, ContactFax, CompanyName, and UserID are not set -->
    </PostingAccount>
    <PostLoads><!-- for removes this would be a RemoveLoads tag -->
        <load><tracking-number>493266</tracking-number><origin><city>BUENA PARK</city><state>CA</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>04</day><hour>12</hour><minute>00</minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></origin><destination><city>CORAL SPRINGS</city><state>FL</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>04</day><hour>12</hour><minute>00</minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></destination><equipment><v></v></equipment><loadsize fullload="true"><length>53</length><width></width><height></height><weight>09</weight></loadsize><load-count>1</load-count><stops>0</stops><distance>2600</distance><rate>0.00</rate><comment>DRY VAN</comment></load>
        <load><tracking-number>433693</tracking-number><origin><city>HARBESON</city><state>DE</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>03</day><hour></hour><minute></minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></origin><destination><city>DETROIT</city><state>MI</state><postcode></postcode><county></county><country></country><latitude>NaN</latitude><longitude>NaN</longitude><date-start><year>2009</year><month>06</month><day>05</day><hour></hour><minute></minute></date-start><date-end><year></year><month></month><day></day><hour></hour><minute></minute></date-end></destination><equipment><r></r></equipment><loadsize fullload="true"><length>48</length><width></width><height></height><weight>42</weight></loadsize><load-count>1</load-count><stops>0</stops><distance>1</distance><rate>0.00</rate><comment></comment></load>
    </PostLoads>
</PELoadPostings>

1 个答案:

答案 0 :(得分:0)

以最常见的方式,轨道中的所有请求参数都可以通过

获得
params 

控制器中的哈希

因此,您可以通过

获取XML
params[:some_params]

要获取将要发送的参数名称,您应该联系将发送它们的第三方服务。

或者可以在Rails应用程序的开发/生产.log中看到params。