How to retrieve the XML from a POST API

My Rails app. needs to retrieve XML statistical data from another site’s
API. To get the XML page, I need to POST the username and password and
date for the stats.

So far I have managed to do this:
within my app, I created a form with the (hidden) username, password,
date and post it to the proper url… this causes my brower to redirect
to the API page and sure enough I see the XML.

Then I copy the XML, go BACK (with my browser)to my app, and I paste it
into a textbox in my app. I submit this and I am able to properly parse
the XML.

What I can’t figure out is this:
how do I get my app to automatically retrieve the XML so that I don’t
have to cut and paste it? Any help would be appreciated!

You have the form post back you your app, which takes the login data and
wgets (Net::HTTP, or what not) the XML for itself.

Jason

Jason R. wrote:

You have the form post back you your app, which takes the login data and
wgets (Net::HTTP, or what not) the XML for itself.

Jason

Thanks for the info Jason. At least I know which direction to look now.
I didn’t quickly find much documentation on ‘wgets’, but have time to
look later tomorrow. I do have a few things I am wondering about now:

  1. the API I need to access will not work unless I POST the parameters
    to it. Can I include POST data in the wgets function call?
  2. Can anyone recommend a book with good details about doing this?

Thanks All! - Tenzing

I got it!

the_url = ‘http://www.the_data.com/report.php’
user_name = ‘joeshmo’
password = ‘happy’
date = ‘2007-06-01’

res = Net::HTTP.post_form(URI.parse(the_url), {:user_name => user_name,
:password => password, :date => date})

parse_this_xml = res.body

#Thanks for the clue Jason!

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs