How to submit a form and get response content

C

Camael Ye

I have a login page,it includes a form,this form includes two text,one
is username and another is password.By manual,when you input
username,password and click submit button,you will see a welcome page,my
question is how to submit a form and get welcome page's content by ruby
code,now,I can post username and password data into login page but I
cannot submit this page success and get welcome page.

require 'net/http'
require 'uri'
url = "http://192.168.1.3:8081/cstk-auto/login/logout.action"

uri = URI.parse(url)
puts uri.host
puts uri.port
http = Net::HTTP.start(uri.host, uri.port)
response = http.request_post(uri.path,"username=admin&password=123456")
puts response.inspect
if (response.code[0,1] == "2" && response.body != "0")
puts response.body
end

Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top