[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Strange error with HTTPS request

Gary Thomas

4/29/2007 6:23:00 AM

I am interested in downloading, from the New Zealand TAB (Totalisator Agency
Board) website, the names of the race meetings on a particular date. This is
normally reached from the TAB main page (www.tab.co.nz) through their
results page which has a form with date dropdown (and uses HTTPS). Picking
(for example) 20 April 2007 leads to a web page with the URL
ebet.tab.co.nz/ebet/ResultsArchive?day=20&month=04&year=2007

If I copy this URL and paste it into another instance of my web browser
(Mozilla), it produces the correct list of meetings. On the other hand, if I
try and access it through Ruby, I get a zero length response body (and an
obscure error if I switch on the debug as in the example below). My code is:

uri =
URI.parse('https://ebet.tab.co.nz/ebet/ResultsArchive?day=20&month=04&...
007')
request = Net::HTTP.new(uri.host, uri.port)
request.set_debug_output $stderr
request.use_ssl = true
request.verify_mode = OpenSSL::SSL::VERIFY_NONE
response = request.get2(uri.path)
puts response.body.size

If I pass the parameters as a second parameter, hashed, to the get2 call I
get exactly the same results (that is, an error).

Can someone point out my mistake in this code which works pretty well in
other situations?

Gary Thomas



1 Answer

Aaron Patterson

4/29/2007 10:09:00 AM

0

On Sun, Apr 29, 2007 at 03:23:25PM +0900, Gary Thomas wrote:
> I am interested in downloading, from the New Zealand TAB (Totalisator Agency
> Board) website, the names of the race meetings on a particular date. This is
> normally reached from the TAB main page (www.tab.co.nz) through their
> results page which has a form with date dropdown (and uses HTTPS). Picking
> (for example) 20 April 2007 leads to a web page with the URL
> ebet.tab.co.nz/ebet/ResultsArchive?day=20&month=04&year=2007
>

[snip]

>
> Can someone point out my mistake in this code which works pretty well in
> other situations?

Do you really need to use Net::HTTP? I was able to fetch the page with
mechanize and not have to deal with setting up Net::HTTP:

require 'rubygems'
require 'mechanize'

mech = WWW::Mechanize.new
page =
mech.get('https://ebet.tab.co.nz/ebet/ResultsArchive?day=20&month=04&year...)
puts page.body.length

Hope that helps!

--
Aaron Patterson
http://tenderlovem...