Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > How to POST Form Data?

Reply
Thread Tools

How to POST Form Data?

 
 
Darshana Gangwal
Guest
Posts: n/a
 
      07-05-2010
Hello,

I am trying to post the form (http) from the below html "test.html" and
am using the below ruby code "submit_test.rb" to submit the form but
getting html response page with message
"Unhandled Request: The server is not setup to handle this type of
Request:" instead of search result from keyword "technology".
can anyone give any pointer to get the proper search result?

test.html
--------------------------------------------------------------------
<html>
<body> <h2>Submit This!!!</h2>
<form action =
"http://www.chamberdata.cc/ccao/wc.dll?Mem~KeywordList~&Org=txallen"
method = "post">
<input type = "text" value = "" name = "Keyword">
<button type = "submit" value = "submit" name = "click me">
</form>
</body>
</html>
--------------------------------------------------------------------

submit_test.rb
--------------------------------------------------------------------
require 'rubygems'
require 'nokogiri'
require 'uri'
require 'net/http'

def submit_form
form_map = Hash.new
file_name = "test.html"
html_content = get_file_content(file_name)
url = extract_url_str(html_content)
form_map['Keyword'] = "technology" # keyword to be submitted
form_map['click me'] = "submit"

# submit form
response = Net::HTTP.post_form(URI.parse(url), form_map)
response_body = response.body if Net::HTTPSuccess
p "response_body #{response_body}"
end

def extract_url_str(response_body)
url_str = ""
doc = Nokogiri::HTML(response_body)
form_array = doc.search("form")
if form_array.nil? then
raise "form_array == nil"
end

form_array.each { |form|
if form.get_attribute("action").include?("KeywordList ") then
url_str = form.get_attribute("action")
break
end
}
return url_str

end

def get_file_content(file_path)
file = File.open(file_path,"r")
html_response = file.read
return html_response
end

submit_form
--------------------------------------------------------------------
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: How include a large array? Edward A. Falk C Programming 1 04-04-2013 08:07 PM
Multiple Form Post Using Javascript - Empty Post from FF Adam Javascript 8 11-24-2005 12:03 PM
Post post post. Shel-hed Computer Support 2 11-08-2003 07:41 AM
Can post form data in IIS, but doesnt post it via webserver J. Muenchbourg Javascript 0 08-06-2003 05:23 PM
ASP, FORMS, POST METHOD And Post with out form(???) Don Glover the younger ASP General 0 07-13-2003 02:47 AM



Advertisments