New Discussion

Notifications

You’re not receiving notifications from this thread.

Make http POST request that return xml response

1
Rails

I want to make a http POST request that parse XML response and return the value of SessionId field that is inside XML. This is what I tried so far but I want to return SessionId filed that arrives with the response and I don't know if this is the right approach to have a xml response.
Ps: is there a way I can run this class from the console, in the way that I can see the response?

class Documents::CreateSession

def initialize()
@username = Rails.secrets.legal_doc.username
@password= Rails.secrets.legal_doc.password
end

def start

require "net/http"
require "uri"

uri = URI.parse("http://example.com/search")

http = Net::HTTP.new(uri.host, uri.port)

request = Net::HTTP::Post.new(uri.request_uri)
request.set_form_data({"userid" => @username, "password" => @password})

response = http.request(request)

end

end

You can run that code in the console by running the same code as you would in your app. response = Documents::CreateSession.new.start

The response will be the return value of start as it currently is setup.

Join the discussion
Create an account Log in

Learning Ruby on Rails? Join our newsletter.

We won't send you spam. Unsubscribe at any time.