Matt Garrish wrote:
> "Adrian" <> wrote in message
> news: oups.com...
> > Hi Guys,
> >
>
> What about the women?
>
> >
> > I am a total Perl newbie and I need some help with a simple script.
> >
>
> If the script is so simple, why haven't you made any effort to write
it
> yourself?
>
> >
> > I need a script to download a file via HTTP. The tricky bit is that
I
> > am behind a proxy server which requires authentication and the
website
> > where the file resides also requires authentication.
> >
>
> That is tricky. Even if someone were to write an example for you, and
don't
> hold your breath, you give no information about how your supposed to
> authenticate.
>
> >
> > Can you please post an example of a script that authenticates
through a
> > proxy and then authenticates against a remote website and downloads
a
> > file.
> >
>
> No, but if you run into a problem you can't solve through the docs or
by
> googling you're free to post here again for help.
>
> Matt
Here is my solution.
Hopefully it helps the next person with a similar problem.
#! /usr/bin/perl -w
# client1.pl - a simple client
#----------------
use strict;
use Socket;
use FileHandle;
my $server = 'NAME OF PROXY GOES HERE';
my $portNumber = 8080;
my $proxyUserPassBase64 = 'BASE 64 ENNCODED ProxyUser

roxyPassword
GOES HERE';
my $path = 'http://NAME OF EXTERNAL SITE GOES HERE:80/';
my $websiteUserPassBase64 = 'BASE 64 ENNCODED User

assword GOES
HERE';
# initialize host and port
my $host = shift || $server;
my $port = shift || $portNumber;
# get the port address
my $iaddr = inet_aton($host);
my $paddr = sockaddr_in($port, $iaddr);
# create the socket, connect to the port
socket(SOCKET, PF_INET, SOCK_STREAM, 0) or die "socket: $!";
connect(SOCKET, $paddr) or die "connect: $!";
autoflush SOCKET (1);
######### Send HTTP GET request
print SOCKET "GET $path HTTP/1.1\n";
print SOCKET "Host: $host\n";
print SOCKET "Connection: close\n";
print SOCKET "Authorization: Basic\n ";
print SOCKET "$websiteUserPassBase64\n";
print SOCKET "Proxy-Authorization: Basic\n ";
print SOCKET "$proxyUserPassBase64\n";
print SOCKET "Accept: text/html; */*\n";
print SOCKET "\n";
######### Receive HTTP response via SOCKET
my $data;
while ( <SOCKET> ) {
chomp;
$data .= "$_\n";
}
######### SOCKET (close); take down the session
close(SOCKET);
open OUTPUT, ">output.txt";
print OUTPUT $data;
close OUTPUT;
Cheers,
Adrian