Topic: NET HTTP POST XML returned.. need help

I'm new to Ruby and to Rails. I'm trying to build an app that consumes another XML based API web service and I'm stuck. Please let me know if I am doing something wrong.I need to POST XML to a URL. When I do this, the web service that I am posting to returns XML. I need to set that XML as a Ruby object and extract the value of an attribute. So, this is what I have in my controller:

require 'net/http'

class ServersController < ApplicationController

  def index(myURL="http://myxmlserviceapi.com", myName="xuser", myPassword="foo")

    @url = myURL

    @uri = URI.parse @url

    xml_req = "<xLogin inName='#{myName}' inPassword='#{myPassword}'></xLogin>"

    request = Net::HTTP::Post.new(@url)

    request.body = xml_req

    http = Net::HTTP

    #left off here need to parse the xml and look for the value of the outCookie attribute within the "xLogin" tag returned by the xLogin POST
    #sample xml returned by POST: <XLogin cookie="" response="yes" outCookie="1357323804/bace9755-0445-496b-973a-0dfaf23d26c1" outRefreshPeriod="600"> </XLogin>

      #session[myCookie=>"thisCookieValue"]

  end

end

Then, just for kicks in my index view file index.html.erb I'd like to do something like this:

<h2><%= session[myCookie %></h2>

Can anyone offer some advice to help me get unstuck here?

Last edited by the1drewharris (2013-01-10 10:44:22)