0

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.

the Tin Man
161k44 gold badges222 silver badges308 bronze badges
asked Jan 28, 2011 at 12:27
5
  • 5
    Please post the ruby code you have tried and explain how it's failing rather than looking for someone else to do this for you. Commented Jan 28, 2011 at 12:30
  • What you have posted here is syntactically correct Ruby, so I'm not sure exactly what your question is? Commented Jan 28, 2011 at 13:19
  • @philosodad: almost, but you'd need an extra ".new" to create the instance. Commented Jan 28, 2011 at 14:19
  • As a stylistic thing, in Ruby semicolons closing a statement are optional unless multiple statements are on the same line. So, in your example code, any use of ; at a line end is wasted and, for readability should be removed to get rid of some line-noise. Commented Jan 28, 2011 at 15:20
  • @tokland: true, unless GetXmlHttpObject is the name of a method that returns a new object, perhaps a one of a selection based on context. Commented Jan 29, 2011 at 2:58

2 Answers 2

1

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.

answered Jan 28, 2011 at 15:31
Sign up to request clarification or add additional context in comments.

Comments

0

Can you post some code? 2 hints: rest-client + ActiveSupport's Hash#to_xml. Probably you'll need one line of code.

answered Jan 28, 2011 at 14:16

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.