Displaying the html from a ruby .cgi script

M

Marc Heiler

I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

It generates html code. I am using Apache on Linux here,
everything is local only.

My question is:

Is there an easy way to grab that generated html code and
display it (as a long string) on a console?

I thought lynx -dump might help but it doesn't, plus it is
not a "ruby only" solution, which I would prefer (since
I'd like this to work on windows as well, even without
lynx around)
 
A

Albert Schlef

Marc said:
I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

[...]
Is there an easy way to grab that generated html code and
display it (as a long string) on a console?
[...]
a "ruby only" solution, which I would prefer

require 'open-uri'
print open('http://localhost/foobar.cgi').read

I thought lynx -dump might help but it doesn't,

What does "it doesn't" mean? If it means "but I don't see the HTML",
then that because you should've used -source, not -dump.
 
B

Brian Candler

Marc said:
I have a script, foobar.cgi

I can load it into my browser, as in
http://localhost/foobar.cgi

It generates html code. I am using Apache on Linux here,
everything is local only.

My question is:

Is there an easy way to grab that generated html code and
display it (as a long string) on a console?

(1) curl http://localhost/foobar.cgi

With appropriate command-line options you can also POST to the CGI
easily enough. (Maintaining a session with cookies would be more awkward
though)

(2) I believe you should just be able to run the CGI from the command
line:

/path/to/foobar.cgi
or
ruby /path/to/foobar.cgi

in which case it'll prompt you for any parameters, then press ^D to get
the response.

(3) The very manual way:

telnet localhost 80
GET /foobar.cgi HTTP/1.0
Host: localhost
<Enter>
 

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