Many people assume "telnet" is a simple raw network connection, and is thus suitable anytime you want to connect and test some TCP port. This really isn't the case. There is, in fact, a "telnet protocol" that describes all sorts of terminal negotiation. No doubt, this is what
Net::Telnet was built for, so no, I don't expect this was what you were wanting.
Try using a simple IO::Socket to set up a TCP connection to your web server. You can then freely read and write to it as you need to.
my $s = new IO::Socket::INET ("www.example.com:80")
or die "Couldn't connect: $!";
print $s "GET / HTTP/1.0\n\n";
if (<$s> =~ /HTTP\S+ ([345].*)/) {
die "Error: $1";
}
...
An alternative (as another poster mentioned) is to use the
LWP modules, which offer a complete HTTP client library.
use LWP::Simple; # or you could do more advanced stuff
my $results = get("http://www.example.com/");
if (!defined($results)) {
die "Error!";
}
...
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.