Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > posting form data in ruby 1.8.2?

Reply
Thread Tools

posting form data in ruby 1.8.2?

 
 
7stud --
Guest
Posts: n/a
 
      09-16-2007
Hi,

I'm trying to figure out how to post form data to a url, but the methods
used in the examples in the Net::HTTP docs use methods that aren't
available in my ruby install:


Posting Form Data:

require 'net/http'
require 'uri'

#1: Simple POST
res =
Net::HTTP.post_form(URI.parse('http://www.example.com/search.cgi'),
{'q'=>'ruby', 'max'=>'50'})
puts res.body

#2: POST with basic authentication
res =
Net::HTTP.post_form(URI.parse('http://jack(E-Mail Removed)/todo.cgi'),
{'from'=>'2005-01-01',
'to'=>'2005-03-31'})
puts res.body

#3: Detailed control
url = URI.parse('http://www.example.com/todo.cgi')
req = Net::HTTP:ost.new(url.path)
req.basic_auth 'jack', 'pass'
req.set_form_data({'from'=>'2005-01-01', 'to'=>'2005-03-31'}, ';')
res = Net::HTTP.new(url.host, url.port).start {|http|
http.request(req) }
case res
when Net::HTTPSuccess, Net::HTTPRedirection
# OK
else
res.error!
end



I looked at the source code for the methods that cause missing method
errors, and I tried to use the lower level methods used in the source,
but some of them weren't available either, which required that I look
into more source files, and eventually I got lost in a labyrinth. Here
are my feeble beginnings:

require "net/http"
require "uri"

url = URI.parse("https://login.yahoo.com/config/login?")
puts url.path
puts url.port

req = Net::HTTP:ost.new(url.path)
#req.content_type = 'application/x-www-form-urlencoded'
#req.body = "username=tailing_loop2003&passwd=bwopmd"
#I get an error saying there is no content_type= method.

#response = Net::HTTP.post_form("https://login.yahoo.com/config/login?",
{"username", "aaaaaa", "passwd", "bbbb"})
#No post_form method.


Is there an example online that I can look at somewhere? I can't find
anything in pickaxe2 or ruby way2.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Bil Kleb
Guest
Posts: n/a
 
      09-16-2007
7stud -- wrote:
> Hi,


Hi.

> Is there an example online that I can look at somewhere? I can't find
> anything in pickaxe2 or ruby way2.


Try Mechanize: http://mechanize.rubyforge.org/

Regards,
--
Bil Kleb
http://fun3d.larc.nasa.gov
 
Reply With Quote
 
 
 
 
Michael Linfield
Guest
Posts: n/a
 
      09-17-2007

> #req.content_type = 'application/x-www-form-urlencoded'


> #I get an error saying there is no content_type= method.
>
> #response = Net::HTTP.post_form("https://login.yahoo.com/config/login?",
> {"username", "aaaaaa", "passwd", "bbbb"})
> #No post_form method.
>
>

content_type should be in () IE: content_type=(type, params = {})
instead of quotes

same type of scenario for no post_form method

Net::HTTP:ost_form(url, params)

have fun!
--
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
posting to a form with no form name scripteaze@gmail.com Python 3 11-02-2007 08:29 AM
Top Posting vs. Bottom Posting scaredkitty Computer Support 37 04-06-2005 12:27 AM
Posting form content to remote servers form? Rob Meade ASP .Net 0 12-01-2004 12:56 PM
Everytime I hover cursro over a posting, it crosses out with red mark on it.. on every posting alanb ASP .Net 2 04-23-2004 02:23 PM
WebClient form Posting with form name? Jeff Baker ASP .Net 2 08-29-2003 12:22 PM



Advertisments