Velocity Reviews - Computer Hardware Reviews

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

Thread Tools

How to POST Form Data?

Darshana Gangwal
Posts: n/a

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?

<body> <h2>Submit This!!!</h2>
<form action =
method = "post">
<input type = "text" value = "" name = "Keyword">
<button type = "submit" value = "submit" name = "click me">

require 'rubygems'
require 'nokogiri'
require 'uri'
require 'net/http'

def submit_form
form_map =
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}"

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

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


def get_file_content(file_path)
file =,"r")
html_response =
return html_response

Posted via

Reply With Quote

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