Link to home
Start Free TrialLog in
Avatar of heit
heit

asked on

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?
Avatar of ozo
ozo
Flag of United States of America image

Authorization: Basic <base64 encoded user:password>
Avatar of heit
heit

ASKER

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?
$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
Avatar of heit

ASKER

Adjusted points to 250
Avatar of heit

ASKER

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!
Avatar of heit

ASKER

ozo > what's that 'lwp-request' .. is that an unix-application? or part of the http-handshake?
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of heit

ASKER

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
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! :)


Avatar of heit

ASKER

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?
Oops sorry, my mistake :0

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

plz try again.

tha fox
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

Avatar of heit

ASKER

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