[prev in list] [next in list] [prev in thread] [next in thread] 

List:       ruby-talk
Subject:    Re: nuby: can't get an image via http
From:       Emmanuel Touzery <emmanuel.touzery () wanadoo ! fr>
Date:       2004-01-27 10:22:54
Message-ID: 40163C8E.7010400 () wanadoo ! fr
[Download RAW message or body]

Guido de Melo wrote:

> Hi,
> 
> I want to download maps from chizumaru, they provide good digital maps 
> and I want to put them together so I get a big map of Tokyo for example.
> 
> Now wget works as it should:
> wget -O test.png 
> 'http://ras.chizumaru.com/ncg/tcmap.dll?id=NCZ&PASS=NewCZPrtT&X=129374719&Y=103205254&LV=3&WID=650&HEI=680&SZ=PRT_T&TAB=live2003_scl&FUNC=2' \
>  
> 
> But I wanted to do this in Ruby so I tried this:
> 
> require 'net/http'
> require 'uri'
> 
> # this works
> Net::HTTP.get_print(URI.parse('http://ras.chizumaru.com/ncg/tcmap.dll?id=NCZ&PASS=Ne \
> wCZPrtT&X=129374719&Y=103205254&LV=3&WID=650&HEI=680&SZ=PRT_T&TAB=live2003_scl&FUNC=2')) \
>  
> 
> 
> but then I have to redirect the output on the console. If I do it this 
> way
> 
> mapfile = File.new("map.jpg", "w")
> 
> Net::HTTP.start('ras.chizumaru.com', 80) {|http|
> response, data = http.post('/ncg/tcmap.dll', 
> 'id=NCZ&PASS=NewCZPrtT&X=129374719&Y=103205254&LV=3&WID=650&HEI=680&SZ=PRT_T&TAB=live2003_scl&FUNC=2') \
>  
> mapfile.puts data
> }
> 
here is my version. i works a bit better, but still produces a corrupted 
file under windows (probably due to the binary flags or something). i 
think it should work under linux.
===============
require 'open-uri'

mapfile = File.open('map.png', 'wb')
open 
('http://ras.chizumaru.com/ncg/tcmap.dll?id=NCZ&PASS=NewCZPrtT&X=129374719&Y=103205254&LV=3&WID=650&HEI=680&SZ=PRT_T&TAB=live2003_scl&FUNC=2') \
 {|f|
    f.binmode
    mapfile.write f.read
}
mapfile.close
==============

i don't really understand why it doesn't work?

emmanuel


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic