RoR noob在这里...... :)
我需要创建一个Rails API,客户端可以通过POST请求调用并发送XML文件.
我创建了这样的路线:
namespace :api do
namespace :v1 do
resource :report
end
end
Run Code Online (Sandbox Code Playgroud)
我的控制器是这样的:
class Api::V1::ReportsController < ApplicationController
respond_to :xml
def create
@report_submission = ReportSubmission.create :login => params[:login],
:status => :success
respond_with(@report_submission)
end
end
Run Code Online (Sandbox Code Playgroud)
我需要在控制器中接收客户端将要发布的XML文件,然后读取内容,以便最终将其放入数据库中?
我怎么测试呢?
我已经创建了一个沙盒项目来尝试这个并且卡住了......不知道下一步该做什么.我把它推到了这里:
https://github.com/claudiolassala/api-samples/
任何帮助都会很棒!结束
我正在尝试使用HTTParty发出POST请求,其中我需要内容类型为text/xml.我怎么能做到这一点?现在我正在调用的API抱怨我没有发送任何xml.如果我使用curl调用它,我会得到相同的错误,除非我将content-type指定为text/xml.