在我的Rails 4應用程序中,我正在處理只處理XML的API(是的,我希望它也是JSON)。Rails和XML請求
我必須做一個POST請求,並且XML字符串應該存儲在一個名爲xmlRequestString
的參數中。
爲POST數據的XML結構爲:
<?xml version="1.0" encoding="UTF-8"?>
<GetProperties>
<Auth>
<VendorId>UserID</ VendorId>
<VendorPassword>Password</VendorPassword>
</Auth>
</GetProperties>
因爲我從來沒有碰過XML之前可能有人告訴我我怎麼會真的發表了這一數據。
會是這樣的一個很好的方式去做它(從這裏借:Submitting POST data from the controller in rails to another website)?
require "uri"
require "net/http"
xml = 'xml string can go here'
params = {'xmlRequestString' => xml}
Net::HTTP.post_form(URI.parse('urlendpoint'),params)
你可以列出你已經先嚐試? – kddeisz