我在Rubyforge上看到的,它的0.1版本将第一行的代码注释掉了,代码是不能运行的,我将第一行的注释去掉了,代码可以工作了,enjoy it!
require 'net/https'
def GoogleLogin(username, password)
url = URI.parse('https://www.google.com/accounts/ClientLogin')
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
res = http.start do |http|
req = Net::HTTP::Post.new(url.path)
req.set_form_data({'Email'=>username, 'Passwd'=>password, 'service'=>'xapi', 'source'=>'rails-plugins'},'&')
http.request(req)
end
case res
when Net::HTTPSuccess #, Net::HTTPRedirection
true
else
false
end
end
#测试
if GoogleLogin('boy.365@126.com ','mypassword')
puts "suc"
else
puts "failed"
end