Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
posting form data in ruby 1.8.2?
7stud 7stud
9/16/2007 10:41:00 AM
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/searc...
),
{'q'=>'ruby', 'max'=>'50'})
puts res.body
#2: POST with basic authentication
res =
Net::HTTP.post_form(URI.parse('http://jack:pass@www.example.com/todo.cgi'),
{'from'=>'2005-01-01',
'to'=>'2005-03-31'})
puts res.body
#3: Detailed control
url = URI.parse('
http://www.example.com/tod...
)
req = Net::HTTP::Post.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/lo...
)
puts url.path
puts url.port
req = Net::HTTP::Post.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/lo...
,
{"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-...
.
2 Answers
Bil Kleb
9/16/2007 11:51:00 AM
0
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.ruby...
Regards,
--
Bil Kleb
http://fun3d.lar...
Michael Linfield
9/17/2007 7:31:00 AM
0
> #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/lo...
,
> {"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::post_form(url, params)
:) have fun!
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
posting form data in ruby 1.8.2?
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password