1

I am trying to post an XML to an API which returns me an XML. I successfully did that by executing a simple CURL command

curl "http://my.server.com/api/identity/emails_from_ids" 
--proxy dvaic.snv.fex:80 -d "<users><id>3434</id></users>" 
-X POST -H 'Content-Type: application/xml' -u admin:admin

The above command executes successfully. I would like to do the same using Rails now. How to do it? I went through the Net::Http documentation but I cannot decipher much from it.

Thanks

bragboy
  • 34,892
  • 30
  • 114
  • 171

2 Answers2

1

And what about this one?

Net::HTTP::Proxy("dvaic.svn.fex", 80, "admin", "admin").start("my.server.com", 80) do |http|
  response = http.post("/api/identity/emails_from_ids", 
                       "<users><id>3434</id></users>", 
                       {"Content-Type" => "application/xml"})
  # ... response.body <== Response with XML
end
bragboy
  • 34,892
  • 30
  • 114
  • 171
Radek Paviensky
  • 8,316
  • 2
  • 30
  • 14
0

You can call it directly in system

%x{curl "http://my.server.com/api/identity/emails_from_ids" 
--proxy dvaic.snv.fex:80 -d "<users><id>3434</id></users>" 
-X POST -H 'Content-Type: application/xml' -u admin:admin}
shingara
  • 46,608
  • 11
  • 99
  • 105
  • I do not want to do it this way as I have to hard code the username and password. – bragboy Sep 28 '10 at 08:05
  • You can update your command with some variables like explain in this question : http://stackoverflow.com/questions/3810290/rails-curl-syntax – shingara Sep 28 '10 at 08:24
  • I cannot use CURL because my team is running the same app in local on Windows. And this introduces a dependency that the place whereever this application runs, curl should be there. My question would be is it possible to do it in Rails – bragboy Sep 28 '10 at 08:29