0

I am passing xml data from an xml for post_xml to a web service which reads this data but am getting an error # my passing method is as below. What am I missing out or how shoul i go about it. Thank you

require 'net/http'
require 'open-uri'

pegPayStatusCode = ""
conn = Net::HTTP.new(uri.host, uri.port)
request = Net::HTTP::Post.new(uri.request_uri)
   if uri.scheme == 'https'
    require 'net/https'
    conn.use_ssl = true
    conn.verify_mode = OpenSSL::SSL::VERIFY_NONE   # needed for windows environment
  end
#request.body=post_xml

request.set_form_data({"q" => "#{post_xml}", "per_page" => "50"})
response = conn.request(request)

pegPayStatusCode = response
Chris Heald
  • 61,439
  • 10
  • 123
  • 137
Becka
  • 124
  • 1
  • 11
  • Have you tried fixing the problem that causes the error? (Until you tell us what the error *actually is* this is about the best answer you're going to get) – Chris Heald Jan 16 '14 at 20:13
  • there is nothing you do about internal server error from the client, except your request is wrong and the server is not responding with a friendly error code – bjhaid Jan 16 '14 at 20:33
  • But hwen you look at my code above, is it the best way of passing xml form data to any web service? – Becka Jan 16 '14 at 20:39
  • Using `"#{post_xml}"` is definitely not the right way to do it. XML is a string, `post_xml` should be a string, so why interpolate a string into a string? – the Tin Man Jan 16 '14 at 21:06
  • Don't name variables in Ruby using camelCase: `pegPayStatusCode`. Use snake_case: `peg_pay_status_code`. – the Tin Man Jan 16 '14 at 21:07
  • i have edited my code as you said instead of using request.set_form_data({"q" => "#{post_xml}", "per_page" => "50"}) I have removed it and am using request.body=post_xml.join but am still getting the same error – Becka Jan 17 '14 at 11:10
  • I just need to know how to execute that xml string. – Becka Jan 17 '14 at 11:19

0 Answers0