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";

In reply to Sending SMS msgs to AT&T phone / Coping with forms that want cookies by dws

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.