How do I convert the following JavaScript code into Ruby?
xmlhttp = GetXmlHttpObject();
xmlhttp.open("POST", "valid_from_f_nav.asp", false)
str="<package><username>"+ username + "</username><password>" + password + "</password></package>";
xmlhttp.send(str)
str = xmlhttp.responseText;
I need to keep the cookies I receive from the HTTP POST request.
2 Answers 2
Ruby's Mechanize gem is probably a good starting point. It supports POST, along with automatically providing a cookie jar. It's built on top of the Nokogiri XML/HTML parser, so once you've retrieved the page or data you can easily navigate it to extract out the interesting bits.
Look through the docs, and if you need additional information edit your original question and add the URL you're working with, plus sample code and we'll try to help.
Comments
Can you post some code? 2 hints: rest-client + ActiveSupport's Hash#to_xml. Probably you'll need one line of code.
;at a line end is wasted and, for readability should be removed to get rid of some line-noise.GetXmlHttpObjectis the name of a method that returns a new object, perhaps a one of a selection based on context.