LWP-problems

R

Ronny Mandal

Hello.

I am running the latest ActivePerl on Win32. I utilize the LWP::Simple
and it's get to fetch images from the web.

However, on UNIX, it fetches binary, but on Windows it seems like the
transfer is ASCII. I cannot find anything about the change of mode in
the doc, anyone knows?


Thanks,

Ronny Mandal
 
S

Sisyphus

Ronny Mandal said:
Hello.

I am running the latest ActivePerl on Win32. I utilize the LWP::Simple
and it's get to fetch images from the web.

However, on UNIX, it fetches binary, but on Windows it seems like the
transfer is ASCII. I cannot find anything about the change of mode in
the doc, anyone knows?

Just binmode the filehandle before you write what you get() to file:

use warnings;
use strict;
use LWP::Simple;

my $url = "http://www.kalinabears.com.au/ameliagall.jpg";

my $content = get($url);

open(WR, ">pic.jpg") or die "Can't open file for writing: $!";
binmode(WR);
print WR $content;
close(WR) or die "Can't close file after writing: $!";

__END__

Cheers,
Rob
 
J

John Bokma

Ronny Mandal said:
Hello.

I am running the latest ActivePerl on Win32. I utilize the LWP::Simple
and it's get to fetch images from the web.

However, on UNIX, it fetches binary, but on Windows it seems like the
transfer is ASCII. I cannot find anything about the change of mode in
the doc, anyone knows?

Script (bare minimum that has this problem)?
 
B

Bart Lateur

Ronny said:
However, on UNIX, it fetches binary, but on Windows it seems like the
transfer is ASCII. I cannot find anything about the change of mode in
the doc, anyone knows?

I'm guessing the server wrongfully describes the content type as text.

If all's well on the server side, LWP always does the right thing, at
least in my experience.
 
R

Ronny Mandal

Just binmode the filehandle before you write what you get() to file:
Yes! The binmode really did the trick. Just the same as when emitting
pictures from .pl


use warnings;
use strict;
use LWP::Simple;

my $url = "http://www.kalinabears.com.au/ameliagall.jpg";

my $content = get($url);

open(WR, ">pic.jpg") or die "Can't open file for writing: $!";
binmode(WR);
print WR $content;
close(WR) or die "Can't close file after writing: $!";

__END__

Cheers,
Rob


Thanks, Rob!

-Ronny Mandal
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top