Edited at

Ruby MechanizeでBasic認証

More than 1 year has passed since last update.


add_auth()メソッドを使う


add_auth()の引数はBasic認証を使うURLの一部、ユーザー名、パスワードです。

require "mechanize"

agent = Mechanize.new
agent.add_auth("https://hoge.com/fuga", "user", "pass")
page = agent.get("http://hoge.com/fuga")


参考

http://www.xmisao.com/2013/10/11/ruby-mechanize-basic-auth.html