Using Curl:
You will need to pass the form login parameters, probably using the POST method. Check the form's HTML to be sure.
To do a POST request with curl, see https://superuser.com/questions/149329/what-is-the-curl-command-line-syntax-to-do-a-post-request.
This might not work for some forms, which implement CSRF. To work-around this, you would need to parse the HTML, find the CSRF token, and pass it as one of the POST request's data parameters.
Next, the login most likely returns a cookie. Your browser normally saves this, and gives the cookie back to the website on each page request. You will need to specify a cookie file. See Send cookies with curl.
There may be some investigation to work-around any more complicated login schemes, depending on the website.
Using an automated web-browser
The much easier alternative, is to use an automated browser, like Selenium webdriver. There are scripting interfaces you can use, like Capybara (a ruby gem). Using Capybara and Selenium to control a browser, you can avoid any techniques that websites might have which makes using CURL difficult (eg. if they detect and block bots).
The disadvantage is that you need to install it. However, once you do, you can use simple commands to do stuff, eg visit('http://www.google.com')
, click_link('Link Text')
, ...
Also, see:
require 'capybara'
session = Capybara::Session.new(:webkit, my_rack_app)
session.within("//form[@id='session']") do
session.fill_in 'Email', :with => 'user@example.com'
session.fill_in 'Password', :with => 'password'
end
session.click_button 'Sign in'