Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > HTTP Get with Proxy authentication

Reply
Thread Tools

HTTP Get with Proxy authentication

 
 
Adrian
Guest
Posts: n/a
 
      01-17-2005
Hi Guys,

I am a total Perl newbie and I need some help with a simple script.

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.

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.

Your help will be greatly appreciated.

Thanks,

Adrian

 
Reply With Quote
 
 
 
 
Matt Garrish
Guest
Posts: n/a
 
      01-18-2005

"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


 
Reply With Quote
 
 
 
 
Adrian
Guest
Posts: n/a
 
      01-18-2005

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 ProxyUserroxyPassword
GOES HERE';

my $path = 'http://NAME OF EXTERNAL SITE GOES HERE:80/';
my $websiteUserPassBase64 = 'BASE 64 ENNCODED Userassword 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

 
Reply With Quote
 
Adrian
Guest
Posts: n/a
 
      01-18-2005
According to The American Heritage Dictionary of the English Language:
"guys: Informal. Persons of either sex."

 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      01-19-2005

"Adrian" <> wrote in message
news: oups.com...
>
> Here is my solution.
> Hopefully it helps the next person with a similar problem.
>


Glad you were able to find a solution on your own, but I doubt many people
will find it useful, especially since it's much easier to use the LWP module
(and that module provides a much greater range of options).

Matt


 
Reply With Quote
 
Adrian
Guest
Posts: n/a
 
      01-19-2005
Matt,

Thank you so much for your help. Its obvious that you are a perl
expert.

Not only that, but you were the only one kind enough to offer your
advice. If only other Perl developers were as helpful as you have
been, I may've even solved this problem sooner.

Also, would it be possible to post your easier and more flexible
solution here so that myself and others may also benefit from it.
Cheers,

Adrian

 
Reply With Quote
 
Matt Garrish
Guest
Posts: n/a
 
      01-19-2005

"Adrian" <> wrote in message
news: oups.com...
>
> Also, would it be possible to post your easier and more flexible
> solution here so that myself and others may also benefit from it.
>


There's no real point in my posting anything, as the documentation does a
much better job:

http://www.perldoc.com/perl5.8.0/lib/lwpcook.html

In your case, take a look at the section on proxies and authentication.

Matt


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
IllegalArgumentException with Socket API and Proxy with Proxy.Type.HTTP Greg Java 4 08-16-2012 08:26 PM
HTTP SOAP/HTTP GET/HTTP POST milan_9211 Software 0 01-10-2011 02:10 PM
Call Web Service using proxy and http authentication wdveloper Python 4 05-15-2009 04:13 AM
HTTP Proxy via HTTP Layer by Perl? nntp Perl Misc 12 10-23-2004 07:52 AM
[OT] http proxy that supports basic authentication? Alex Hunsley Java 1 05-26-2004 01:34 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57