Using Perl to input username and password for website?

J

John

Hello,

I was wondering if there was a way to use Perl
to enter the username and password automatically
in order to access a particular website. The
website that I want to access prompts the user
for the username and password in a pop-up box,
like so :

Username :
Password :

Then there are two buttons which are OK and Cancel.

How do I use Perl to input the username and password
info automatically and "click" the "OK" button?
Initially, I tried to use the following code that
I found on this newsgroup (posted by Gregory Toomey),
but it does not work for my case.

#!/usr/bin/perl
use LWP::Simple;
use strict;

my $result=get("http://username:password\@www.mysite.com/docs/show.htm");



I can see why the above does not work since the website I want to
access asks you to enter the information in a box rather than as shown
in the code above. I also believe that the website is protected by
..htaccess.

Any help would be appreciated. Thanks!


John
 
W

Walter Roberson

:I was wondering if there was a way to use Perl
:to enter the username and password automatically
:in order to access a particular website. The
:website that I want to access prompts the user
:for the username and password in a pop-up box,
:like so :

:Username :
:password :

:Then there are two buttons which are OK and Cancel.

What is the mechanism that the WWW site is using to pop up the box?
Is it using Java? Javascript? Is the pop-up box definitely
different than the normal pop-up credentials box you would get
for other sites?
 
G

Gregory Toomey

John said:
Hello,

I was wondering if there was a way to use Perl
to enter the username and password automatically
in order to access a particular website. The
website that I want to access prompts the user
for the username and password in a pop-up box,
like so :

Username :
Password :

Use basic authentication which need no programming.

http://httpd.apache.org/docs/howto/auth.html

gtoomey
 
J

John

Hello,

I was wondering if there was a way to use Perl
to enter the username and password automatically
in order to access a particular website. The
website that I want to access prompts the user
for the username and password in a pop-up box,
like so :

Username :
Password :

Then there are two buttons which are OK and Cancel.

How do I use Perl to input the username and password
info automatically and "click" the "OK" button?
Initially, I tried to use the following code that
I found on this newsgroup (posted by Gregory Toomey),
but it does not work for my case.

This is a message in reply to Walter Roberson. The website is
protected by .htaccess using the Apache webserver. So, the pop-up
box is not Java or Javascript.


John
 
G

gnari

John said:
(e-mail address removed) (John) wrote in message
This is a message in reply to Walter Roberson. The website is
protected by .htaccess using the Apache webserver. So, the pop-up
box is not Java or Javascript.

have you tried LWP::UserAgent ?
there is a method called credetials()

gnari
 
T

Tad McClellan

John said:
This is a message in reply to Walter Roberson.


No it isn't.

It is a reply to your original post.

If it had been in reply to Walter, then the References: header
would contain a Message-ID for Walter's message.


Please learn how to make your newsreader generate a proper followup.
 
T

Tore Aursand

Dude... This ISN'T what he's asking for...

How do you know? And _what is_ the OP asking for? To me it sounds
obvious that he/she is asking for help on how to authenticate on a web
site which is using .htaccess;

"I also believe that the website is protected by .htaccess."

Right?

Anyway: This isn't a Perl thing at all. Doing this with Perl is no
different from doing it with any other language - it all depends on the
server (ie. Apache, in this case).
 
S

Sherm Pendley

How do you know? And _what is_ the OP asking for?

He's asking about writing a *client*, not about configuring a server. He
even used LWP in his code.
Anyway: This isn't a Perl thing at all.

Actually, it is. The OP wants to know how to provide authentication
information using LWP. You could argue that it's an RTFM question - it's
in the LWP docs - or you could argue that it's better directed to the
..modules group.

sherm--
 
T

Tore Aursand

He's asking about writing a *client*, not about configuring a server. He
even used LWP in his code.

That's irrelevant as I see it: The method is excactly the same no matter
what _client_ you are using.

Read the Apache documentation for more information about this. You can't
solve this problem different using a different programming language; The
solution is excactly the same.

How you do it with _the language of your choice_ is another story, of
course.


--
Tore Aursand <[email protected]>
"Writing is a lot like sex. At first you do it because you like it.
Then you find yourself doing it for a few close friends and people you
like. But if you're any good at all, you end up doing it for money."
-- Unknown
 
S

Sherm Pendley

That's irrelevant as I see it: The method is excactly the same no matter
what _client_ you are using.

Read the Apache documentation for more information about this.

Are you being deliberately difficult???

The OP is not asking how to configure a server. He's asking how to write,
in Perl, using LWP, a *client* that provides proper authentication to a
server that's been password-protected.

The answer is exactly the same no matter what server you're connecting to
- Either create an instance of LWP::UserAgent and call its credentials()
method, or subclass LWP::UserAgent and override the
get_basic_credentials() method in the subclass.

sherm--
 
A

Arvin Portlock

Well, you don't say what you want to do AFTER you click
OK, or the browsing/downloading context this is all in.
But maybe something like this would work? It prints the
requested document to your screen. You could also redirect
or save to a file if you wanted.

use LWP;

my $url = 'http://some_url/some_document.html';

my $ua = new LWP::UserAgent;
my $req = new HTTP::Request (GET => $url);

$req->authorization_basic ('username', 'password');
my $request = $ua->request ($req);
die unless $request->code eq '200';
my $page = $request->content;
print $page;
 
J

John

Thanks everyone for your suggestions. I used the LWP::UserAgent route and
it worked. Thanks Arvin, your example was very helpful. Thanks to
gnari as well and everyone who posted in the thread.


John
 

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,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top