quik77
December 22, 2009, 11:49pm
1
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)
quik77
December 23, 2009, 3:04am
2
Marc H. wrote:
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.
quik77
December 25, 2009, 8:17pm
3
On Dec 22, 2009, at 14:49 , Marc H. wrote:
Is there an easy way to grab that generated html code and
display it (as a long string) on a console?
% ruby foobar.cgi < /dev/null
quik77
December 23, 2009, 9:31pm
4
Marc H. wrote:
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
quik77
January 30, 2010, 11:48am
5
Thanks for the help, works nicely!