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'
The target page asks only the correct user name, no password is needed in order to login, the basic_auth method requires two parameters, user name and password, if I leave one out, I’ll get the error, I tried to write it like this “req.basic_auth ‘username‘, ””, but I still cannot login.
Could anyone kindly give me a hint?
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.
You can consider using ruby mechanize gem. a login example will be much simpler(from official site), for this one, you will not need to do the agent cert and private key thing: