SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    http form problems

    I am trying to post data to a html form, I tried doing as described in http://www.ruby-doc.org/stdlib/libdo.../Net/HTTP.html. If I try Net::HTTP.post_form(URI.parse('http://jackass@www.example.com/todo.cgi'),
    {'from'=>'2005-01-01', 'to'=>'2005-03-31'}), it says undefined method post_form. I also get undefined method errors for the other methods described on that page. I have included require 'net/http' and require 'uri', and some of the ofther stuff works. Does anyone know how to do this? Is there another way of posting data to a html form?

  2. #2
    eschew sesquipedalians silver trophy sweatje's Avatar
    Join Date
    Jun 2003
    Location
    Iowa, USA
    Posts
    3,749
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    My ri docs show a different way to post.

    Posting Form Data
    Code:
     
             require 'net/http'
             Net::HTTP.start('some.www.server', 80) { |http|
                 response = http.post('/cgi-bin/search.rb', 'query=ruby')
             }
    Jason Sweat ZCE - jsweat_php@yahoo.com
    Book: PHP Patterns
    Good Stuff: SimpleTest PHPUnit FireFox ADOdb YUI
    Detestable (adjective): software that isn't testable.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You should take a look at www::mechanize its available as a gem so:

    $ sudo gem install mechanize

    That will get it for you. I lets your script easily navigate web pages by clicking links and filling out forms for you.

  4. #4
    SitePoint Member
    Join Date
    Oct 2005
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help, I got it working now

  5. #5
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by dilbo
    Thanks for your help, I got it working now
    Having same problem. Please share your solution.

  6. #6
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    Yakima WA.
    Posts
    100
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There is a snafu in the docs for Net::HTTP. The post_form method is not available with ruby 1.8.2. You must have ruby 1.8.3 or higher for that particular method to work. Here is a workaround for 1.8.2:
    Code:
    require 'net/http'
    
    # post some data to uri:port/page
    
    uri = 'www.example.com'
    port  = 80
    page = '/RPC/foo'
    data = '<foo><bar>Doodle!</bar></foo>'
    
    Net::HTTP.start( uri, port) { |http|
      results = http.post( page, data )
    }
    Hope that helps-

  7. #7
    SitePoint Member
    Join Date
    Nov 2005
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Your fix works. Thanks. For multiple entries, data =
    'fld1=val1&fld2=val2&fld3=val3' does the trick.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •