Search code examples
xmlhttpcurlruby-on-rails-2

Using Curl commands in Ruby on Rails 2


I am wanting to send some XML files over HTTP to a web service in post request. I have the generated XML files and would like to use the following command

curl -F "SUBMISSION=@submission.xml" -F "STUDY=@study.xml" \
     -F "SAMPLE=@sample.xml" https://www.somesite.com/submit

I have no clue how to incorporate the command in Rails 2.

Please could so one suggest me an idea or library that I could use for this purpose.

Cheers


Solution

  • Use the Curb gem, it is a library that wraps cURL in Ruby objects and methods.

    Have a look at the examples on http://taf2.github.com/curb/.

    In your case you will have to use something like

    submission_field = Curl::PostField.content(File.read('submission.xml'), 'SUBMISSION')
    study_field = Curl::PostField.content(File.read('stydy.xml'), 'STUDY')
    
    c = Curl::Easy.http_post("https://www.somesite.com/submit",
                             submission_field, study_field, ...)