I am trying to pass data from the database in XML format to an API. I've written the following code in the controller.
require 'active_support/builder' unless defined?(Builder)
require 'uri'
require 'net/http'
def gen_xml
xml = Builder::XmlMarkup.new
@customers = Customer.find(:all)
url = "http://.......................xml?";
request = Net::HTTP::Post.new(url)
request.add_field "Content-Type", "application/xml"
request.body = xml
uri = URI.parse(url)
http = Net::HTTP.new(uri.host, uri.port)
response = http.request(request)
end
I have created a XML file with XML builder, but I'm not able to pass this XML data to the API. The above code doesn't leave any trace of error or any respective action being preformed in the logs.