Make http POST request that return xml response
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.