Hi,
I've written a basic script below which normally works to grab pages but not from my protected site. Naturally I know the Realm, Username and Password but don't know how to incorporate it into my current program to get access to the pages.
Hope someone out there can help!
Denise 
-----------------------------------------------------
#!/usr/bin/perl
&IOSocket;
sub IOSocket{
use IO::Socket;
$method = "GET";
my @f = split(/\//, $input);
$host = "www.domain.com";; #their domain...
$path = "/their/root/protected"; #protected root etc...
$socket = new IO::Socket::INET( PeerAddr => $host,
PeerPort => 80,
Proto => 'tcp',
Type => SOCK_STREAM, ) or die &printout;
print $socket "$method $path HTTP/1.0\nReferer: $host\n";
print $socket "User-Agent: $ENV{'HTTP_USER_AGENT'}\n\n";
@output = <$socket>;
close ($socket);
}
$FILE="d:/Inetpub/mydomain/file.htm"; #my local domain directory path
open(WRBK,">$FILE");
print WRBK "@output\n";
close(WRBK);
exit;






richjb posted this at 14:05 — 4th October 2000.
They have: 193 posts
Joined: Feb 2000
Example:
http://USER:PASSWORD@yourdomain.com
I guess all you would need to do is change $host to reflect the above format.
Hope that helped.
Richard
richard@brevig.com
Everyone here has a website. It's just that not all are worth posting (Mine!
).
Denise posted this at 20:36 — 4th October 2000.
They have: 19 posts
Joined: Oct 2000
Hi Richard,
Thanks for the advice but it didn't work.
I made $host = "myusername:mypassword\@mydomain.com";
but it didn't recognize the url and died.
Any ideas?
Denise
roBofh posted this at 00:06 — 5th October 2000.
They have: 122 posts
Joined: Jun 2000
It wouldn't, because Perl has no idea that you're trying to connect to an httpd there. I believe that LWP allows you to set Username and Password for basic authentication.
Rob Radez
OSInvestor.com
richjb posted this at 13:22 — 5th October 2000.
They have: 193 posts
Joined: Feb 2000
I think I agree with Rob. The LWP module should allow you to use the authentication format I gave you...as it simply calls a URL.
Richard
richard@brevig.com
Everyone here has a website. It's just that not all are worth posting (Mine!
).
Denise posted this at 19:34 — 5th October 2000.
They have: 19 posts
Joined: Oct 2000
Hi guys,
Thanks, I looked into the LWP function and constructed a routine that certainly does grab pages and write them to a file but even though I now know the constructor that authenticates, I need some help inserting it into the routine below:
-----------------
#!/usr/bin/perl
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
$FILE="d:/Inetpub/mydomain/import.htm";
my $ua = new LWP::UserAgent;
my $request = new HTTP::Request('GET', 'http://www.mydomain.com/index.htm');
my $response = $ua->request($request, $FILE);
if ($response->is_success) {
print $response->content;
} else {
print $response->error_as_HTML;
}
exit;
-------------------
Here is the authetnication:
$ua->credentials('www.mydomain.com', 'realm', 'username', 'password');
In the Perl help files it says that you can use $request like this:
request($request [, $subroutine]);
$subroutine being the authentication call.. but whenever I try to build the authentication call above into $subroutine it just comes up with a syntax error for the "'", or just doesn't do anything and returns 401 access denied.
Any ideas?
Cheers,
Denise