[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

http-header with authorisation

Posted on 2000-01-29
13
Medium Priority
?
171 Views
Last Modified: 2013-12-25
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?
0
Comment
Question by:heit
  • 7
  • 3
  • 3
13 Comments
 
LVL 85

Expert Comment

by:ozo
ID: 2431362
Authorization: Basic <base64 encoded user:password>
0
 

Author Comment

by:heit
ID: 2437807
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
 
LVL 85

Expert Comment

by:ozo
ID: 2442262
$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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:heit
ID: 2442661
Adjusted points to 250
0
 

Author Comment

by:heit
ID: 2442662
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
 

Author Comment

by:heit
ID: 2442682
ozo > what's that 'lwp-request' .. is that an unix-application? or part of the http-handshake?
0
 
LVL 85

Accepted Solution

by:
ozo earned 750 total points
ID: 2443464
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
 

Author Comment

by:heit
ID: 2443884
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
 

Expert Comment

by:mr_who
ID: 2487345
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
 

Author Comment

by:heit
ID: 2487428
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
 

Expert Comment

by:mr_who
ID: 2487469
Oops sorry, my mistake :0

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

plz try again.

tha fox
0
 

Expert Comment

by:mr_who
ID: 2487821
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
 

Author Comment

by:heit
ID: 2488722
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

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

591 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question