Nuby: can't get an image via http

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=NewCZPrtT&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
}

the data doesn’t get written. I also experimented with $defout and
$stdout, but I got nowhere, so I’m grateful if someone could offer me
advice on this one.

Happy rubying,
Guido

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=NewCZPrtT&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