get/post puro Ruby
get e post em ruby puro
1 require 'net/http' 2 require 'net/https' 3 4 http = Net::HTTP.new('profil.wp.pl', 443) 5 http.use_ssl = true 6 path = '/login.html' 7 8 # GET request -> so the host can set his cookies 9 resp, data = http.get(path, nil) 10 cookie = resp.response['set-cookie'] 11 12 13 # POST request -> logging in 14 data = 'serwis=wp.pl&url=profil.html&tryLogin=1&countTest=1&logowaniessl=1&login_username=blah&login_password=blah' 15 headers = { 16 'Cookie' => cookie, 17 'Referer' => 'http://profil.wp.pl/login.html', 18 'Content-Type' => 'application/x-www-form-urlencoded' 19 } 20 21 resp, data = http.post(path, data, headers) 22 23 24 # Output on the screen -> we should get either a 302 redirect (after a successful login) or an error page 25 puts 'Code = ' + resp.code 26 puts 'Message = ' + resp.message 27 resp.each {|key, val| puts key + ' = ' + val} 28 puts data