Operating System - HP-UX
1821297 Members
3174 Online
109632 Solutions
New Discussion юеВ

http get requests by commandline

 
SOLVED
Go to solution
Bill McNAMARA_1
Honored Contributor

http get requests by commandline

How do I formulate http requests for a httpd?

A password will be asked, so I'll have to give input, but in either case, it'd be nice to get some response anyway....

pereal:root> telnet pereal 4242
Trying...
Connected to pereal.guinness.ie.
Escape character is '^]'.
HTTP/1.0
HTTP/1.0 505 OK
MIME-Version: 1.0
Server: HP-ChaiServer/3.0
Date: Wed, 21 Nov 2001 16:37:46 GMT
Connection: close
Content-length: 100
Content-Type: text/html
Connection: close

Request Not Implemented

Cannot process request, not implemen
ted at server.

Unknown HTTP actionConnection closed by foreign host.

It works for me (tm)
9 REPLIES 9
Bill McNAMARA_1
Honored Contributor

Re: http get requests by commandline

just to add I've an apache 1.3.19 server on port 80, that just entering GET will o/p the index.html file.

On the Chai Server, a GET returns:
GET
HTTP/1.0 400 Unintelligible request line: GET
MIME-Version: 1.0
Server: HP-ChaiServer/3.0
Date: Wed, 21 Nov 2001 16:44:03 GMT
Connection: close
Content-length: 97
Content-Type: text/html
Connection: close

Bad Request

Bad request, cannot process. Unintelligible requ
est line: GET
Connection closed by foreign host.


It works for me (tm)
Steven Gillard_2
Honored Contributor

Re: http get requests by commandline

Try:

$ echo "GET /\n" | telnet

Regards,
Steve
Bill McNAMARA_1
Honored Contributor

Re: http get requests by commandline

pereal:root> echo "GET /\n" | telnet pereal 4242
Trying...
Connected to pereal.guinness.ie.
Escape character is '^]'.
HTTP/1.0 400 Unintelligible request line: GET /

Just to mention, it will ask me for a password in a prompt box before loading a page, but I guess that must be loaded from within the homepage...
Later,
Bill
It works for me (tm)
David Lodge
Trusted Contributor

Re: http get requests by commandline

You can use the old:
print HTTP string | telnet machine 80
(For HTTP string - look at the RFC!)

But it's not always the best way - you could code it using netcat or expect...

Or, you can download snarf from the porting centre and use that (best way :-)

dave
Steven Gillard_2
Honored Contributor

Re: http get requests by commandline

hmmm that works on my Apache server. Perhaps try conforming to the RFC :

$ echo "GET / HTTP/1.0\n" | telnet

For the password stuff, if its just using basic authentication, you can include the encrypted user name and password in an Authorization header, eg:

echo "GET / HTTP/1.0\nAuthorization: Basic \n" | telnet

From memory, the encryption is simply a base64 encoding of the username:password - check the HTTP RFC to be sure. Not so easy to generate from the shell, but theres always perl :)

Cheers,
Steve
Bill McNAMARA_1
Honored Contributor

Re: http get requests by commandline

sorry David, you should have got a 10 for the snarf reference...

it allows authentication from commandline..

pereal:root> ./snarf -v ocmpadm:ocmpadm@pereal:4242
http://luser:passwd@pereal:4242 (unknown size)
index.html [\] 0K
609 bytes transferred in 0.00 sec (1392.78k/sec)


and:

pereal:root> ./snarf -v pereal:80
HTTP/1.1 200 OK
Date: Wed, 21 Nov 2001 17:11:34 GMT
Server: Apache/1.3.19 (Unix) ApacheJServ/1.1.1 PHP/4.0.4pl1
Last-Modified: Mon, 22 Oct 2001 11:15:57 GMT
ETag: "8470-692-3bd3ffed"
Accept-Ranges: bytes
Content-Length: 1682
Connection: close
Content-Type: text/html

http://pereal:80 (1K)
index.html [########################] 1K | 5401.39K/s
1682 bytes transferred in 0.00 sec (2841.61k/sec)

Later,
Bill

It works for me (tm)
Bill McNAMARA_1
Honored Contributor

Re: http get requests by commandline

pereal:root> ....... GFkbQ==\n" | telnet pereal 4242
Trying...
Connected to pereal.guinness.ie.
Escape character is '^]'.
HTTP/1.0 500 OK
MIME-Version: 1.0
Server: HP-ChaiServer/3.0
Date: Wed, 21 Nov 2001 17:15:14 GMT
Connection: close
Content-length: 108
Content-Type: text/html
Connection: close

Internal Server Error

Could not process request due to inter
nal server error.

Connection closed by foreign host.

It works for me (tm)
Marco Paganini
Respected Contributor
Solution

Re: http get requests by commandline

Hello Bill,

If you want to get, say, a page that is protected by a password, use WGET, like that:

wget --http-user bill --http-passwd mypassword URL

That does the job nicely and you don't have to deal with obscure echo commands. :)

Regards,
Paga
Keeping alive, until I die.
Steven Sim Kok Leong
Honored Contributor

Re: http get requests by commandline

Hi,

Don't forget the good old lynx. :) A combination of either -dump or -source as well as -auth should be sufficient for your specified needs.

To get HTML source:

# lynx -auth=userid:passwd -source http://host.domain/your.url

To get HTML output:

# lynx -auth=userid:passwd -dump http://host.domain/your.url

Hope this helps. Regards.

Steven Sim Kok Leong
Brainbench MVP for Unix Admin
http://www.brainbench.com