http-header with authorisation

hi,

i'm building a script which should automatically get content from a passwordprotected server. Usually i collect my info by typing

http://user:password@hostname.com


Now i want to do this automatically (and send it to my gsm :-) ). I can get info from a website using a telnet connection to port 80 and then do

get pagename.html

It will return plain html. But that;s for non-protected pages. With protected servers, i get a 401 (authorization required) error. I looked up the RFC but i can;t figure out how it is working ..

Can anybody explain me which header i should send to get the information with my username and password?
heitAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
Authorization: Basic <base64 encoded user:password>
0
heitAuthor Commented:
i;ve seen that line in the rfc .. but how can i send it in a telnet session? and how do i encode my pword/username, is there a program to do this?

can somebody type this first lines out for me?
0
ozoCommented:
$login="user:password";
$res = substr(pack('u', $login), 1);
$res =~ tr|` -_|AA-Za-z0-9+/|;
$padding = (3 - length($login) % 3) % 3;
substr($res,-$padding) = '=' x $padding if $padding;
print "Authorization: Basic $res\r\n";

or
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$ua->credentials($netloc, $realm, $uname, $pass)


or
lwp-request -C user:password http://hostname.com 

or
lwp-request http://user:password@hostname.com
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

heitAuthor Commented:
Adjusted points to 250
0
heitAuthor Commented:
ok, that piece of perl did it's job: i'm now able to create that authorization string.

what i did was

> telnet hostname.com 80

and then IN telnet

 Authorization: Basic wt436439085FU {enter}
 get index.html


And it doesn't respond.. when i don't paste the authorizationstring i do this

> telnet hostname.com 80
 get index.html

and it wil respond with plain html (the 401-script)

So, how do i emulate the correct authorizationstuff with telnet?

BTW, i've increased the points!
0
heitAuthor Commented:
ozo > what's that 'lwp-request' .. is that an unix-application? or part of the http-handshake?
0
ozoCommented:
get index.html HTTP/1.0 {enter}
Authorization: Basic wt436439085FU {enter}
{enter}

lwp-request is a program that comes with the LWP::UserAgent module
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
heitAuthor Commented:
ok, we're almost there :-)

i tried to do the following

> telnet hostname.com 80
get index.html HTTP/1.0 {enter}

and then it starts  to give me HTML inmediately ... i also tried

> telnet hostname.com 80
get /chatboxes/nightshift HTTP/1.0 Authorization: Basic ZFUocCoBZVcMXVL`=

But that results in a 401 too .. what am i doing wrong?

can i give the 'get'-statement in the command line, something like

> telnet hostname.com 80 get index.html?

greets, jesse
0
mr_whoCommented:
Hello Jesse,

The way you started is ok, but you should give the server a little more info. This should do the trick:

telnet hostname 80
#send the following lines
GET /chatboxes/nightshift HTTP/1.0
Host: hostname #change this!#
Accept: text/html, text/plain
Accept-Encoding: gzip, compress
Accept-Language: en
User-Agent: younameit
Authorization: Basic asdfasdasdf==
#end, the output is comming your way now

Just fill in you encrypted password and it should work

Tha fox! :)


0
heitAuthor Commented:
i'm sorry but this doesn't work ..

i adjusted the script as you said and i opened my tlenet session, pasted the stuff and then after a few seconds it says

connection closed by foreign host.

what now?
0
mr_whoCommented:
Oops sorry, my mistake :0

there should be 2 {enters} behind the Authorization: like {\n\n}

plz try again.

tha fox
0
mr_whoCommented:
to oxo,

sorry, the thing i posted is very close to your answer: i will withdraw this answer.

ps: the correct is answer is:

telnet hostname 80
#send the following lines
GET /chatboxes/nightshift HTTP/1.0
Authorization: Basic asdfasdasdf==
{enter}
{enter} <- important!

cya

0
heitAuthor Commented:
ozo > too bad your authorization-maker did not work, in the end i used the following (thanx to MR_WHO)

lynx -auth={name}:{password} http://hostname.com/ -source

this line retrieves one page, put's the html-code to stdev an then exits. That was exactly what i needed.

I guess that if ozo's authorization-maker would work, i could do it in telnet which requires less systempower, but the lynx-trick worked fine for the current program
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Scripting Languages

From novice to tech pro — start learning today.