开发者

Translate Javascript to Ruby

How do I convert the following JavaScript code into Ruby?

xmlhttp = GetXmlHttpObject();
xmlhttp.open("POST", "valid_from_f_nav.asp", fal开发者_开发百科se)
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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜