A simple, anti-bot defensive measure that some sites have put together requires that a POST request be accompanied by a session cookie presented when the form was retrieved. AT&T Message Center uses this technique. The following fragment demonstrates how to work through this barrier and send SMS message to AT&T subscriers.
Please use this responsibly.
# This code fragment demonstrates how to send an SMS text message to
# an AT&T wireless subscriber who has an SMS-enabled cell phone. This
# can be used to send an SMS message to yourself when certain events
# happen on your server/website.
#
# At present, AT&T message center presents a browser with a cookie
# when the SMS message form is retrieved, and won't send an SMS
# message unless the cookie is presented along with the POST to
# their CGI. Below we use HTTP::Cookies to set up a cookie jar to
# hold the cookie, and present it along with the post.
#
# There are a number of SMS packages on CPAN, and they're worth
# exploring. At the time I put this together, I didn't find anything
# there that coped with the cookie requirement.
#
# Please use this responsibly.
#
# 28 June 2002 Dave W. Smith <dws@postcognitive.com>
use HTTP::Request::Common qw(GET POST);
use HTTP::Cookies;
use LWP::UserAgent;
my $messageCenter = "http://www.mobile.att.net/messagecenter";
my $pagersend = "$messageCenter/pagersend.cgi";
# ---- change these as appropriate ----
my $phoneNumber = die "phone number here";
my $msgFrom = "me"; # name or phone number
my $msgSubject = "Test"; # optional subject
my $msgBody = "Hello World!"; # from + subject + body <= 140 chars
# -------------------------------------
# Set up a UserAgent with a cookie jar
my $ua = new LWP::UserAgent();
my $cookies = new HTTP::Cookies();
$ua->cookie_jar($cookies);
# Get the pager request form. This gets the cookie we'll need
# later to send the message.
my $req = GET "$messageCenter/";
my $response = $ua->request($req);
if ( ! $response->is_success() ) {
die "Couldn't get form from message center";
}
# Send the SMS message
$req = POST $pagersend, [
pin => $phoneNumber,
from => $msgFrom,
subject => $msgSubject,
message => $msgBody
];
$response = $ua->request($req);
if ( ! $response->is_success() ) {
die "Can't submit page request";
}
my $content = $response->as_string();
if ( $content !~ m/your message has been submitted/i ) {
die "Server didn't like page request\n";
}
print "Sent\n";
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|