tags:

views:

31

answers:

1

Hi, I'm using the following code to download a page through a POST request:

require 'net/http'
require 'uri'
res = Net::HTTP.post_form(URI.parse('http://example.com'),{'post'=>'1'})
puts res.split("Date")

The URL I originally used has been replaced with example.com

It works great, but when I try to call split (last line) it returns an error:

<main>': undefined methodsplit' for # (NoMethodError)

I'm new to ruby, so I'm confused about this error.

+4  A: 

The method you are calling returns a HTTPResponse object, so you need to leverage that object's methods to get what you want. maybe something like:

require 'net/http'
require 'uri'
res = Net::HTTP.post_form(URI.parse('http://example.com'),{'post'=&gt;'1'})
puts res.body.split("Date")

Notice the body method.

Or, if you want to see all the data returned:

require 'net/http'
require 'uri'
res = Net::HTTP.post_form(URI.parse('http://example.com'),{'post'=&gt;'1'})
puts res.inspect

Hope this helps!

Brian