PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > posting form data in ruby 1.8.2?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
posting form data in ruby 1.8.2?

Réponse
 
LinkBack Outils de la discussion
Vieux 16/09/2007, 11h40   #1
7stud --
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut posting form data in ruby 1.8.2?

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: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/todo.cgi')
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/login?")
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/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/.

  Réponse avec citation
Vieux 16/09/2007, 12h51   #2
Bil Kleb
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: posting form data in ruby 1.8.2?

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
  Réponse avec citation
Vieux 17/09/2007, 08h30   #3
Michael Linfield
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: posting form data in ruby 1.8.2?


> #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::post_form(url, params)

have fun!
--
Posted via http://www.ruby-forum.com/.

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 18h38.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,09898 seconds with 11 queries