English 中文(简体)
采用网络撰写汽车: Http
原标题:Writing autologin using Net::Http in Ruby
  • 时间:2012-05-08 00:34:27
  •  标签:
  • ruby

http://ruby-doc.org/stdlib-1.8.7/libdoc/net/http/rdoc/Net/HTTP.html

After reading the doc very carefully, I m writing the following code snippet for the autologin feature of my program:

url = URI.parse( http://localhost/login.aspx )
req = Net::HTTP::Post.new(url.path)
req.basic_auth  username 

指标网页仅询问正确的用户名称,不需要密码才能登录,如果我离开,用户名称和密码就要求两个参数,即用户名称和密码,那么我就试图把这个错误写成“req.basic_authusername,但我仍然无法登录。

谁能给我一个 h?

more info: I also tried req.basic_auth username , , it didn t seem to be working, I know this because there s another line of line follow right after this one, which is basically doing auto form submission. x = Net::HTTP.post_form(URI.parse("http://localhost/NewTask.aspx"), params) puts x.body

And the puts result came back with the redirect to login page body.

最佳回答

您可考虑使用ruby Mechanicalze gem。 a 标志性的例子将非常简单(从官方网站),因为这样,你不需要做代理人的ert和私人钥匙:

require  rubygems 
require  mechanize 

# create Mechanize instance
agent = Mechanize.new

# set the path of the certificate file
agent.cert =  example.cer 

# set the path of the private key file
agent.key =  example.key 

# get the login form & fill it out with the username/password
login_form = agent.get("http://example.com/login_page").form( Login )
login_form.Userid =  TestUser 
login_form.Password =  TestPassword 

# submit login form
agent.submit(login_form, login_form.buttons.first)
问题回答

暂无回答




相关问题
Ruby parser in Java

The project I m doing is written in Java and parsers source code files. (Java src up to now). Now I d like to enable parsing Ruby code as well. Therefore I am looking for a parser in Java that parses ...

rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

multiple ruby extension modules under one directory

Can sources for discrete ruby extension modules live in the same directory, controlled by the same extconf.rb script? Background: I ve a project with two extension modules, foo.so and bar.so which ...

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

热门标签