#!/usr/bin/perl use warnings; use strict; package MyAgent; use base 'LWP::UserAgent'; sub redirect_ok { my ($self, $request) = @_; return 1; } package URLStateMachine; use HTTP::Request::Common qw(POST); use LWP::UserAgent; use HTTP::Cookies; sub new { my $class = shift; my $args = shift; my $self = { states => $args }; $self->{ua} = new MyAgent; $self->{cookieJar} = new HTTP::Cookies; $self->{ua}->cookie_jar($self->{cookieJar}); return bless($self, $class); } sub run { my $self = shift; my @stateList = @{$self->{states}}; foreach my $state (@stateList) { my $res; $self->logmsg($state->{info}); if ($state->{method} eq 'GET') { $res = $self->{ua}->request(new HTTP::Request(GET => $stat +e->{url})); $res->is_success or $self->logerr($res->status_line); } elsif ($state->{method} eq 'POST') { $res = $self->{ua}->request(POST $state->{url}, $state->{args}); $res->is_success or $self->logerr($res->status_line); } } } sub logerr { my $self = shift; my $msg = shift; print scalar localtime(time) . " ERROR: $msg\n"; } sub logmsg { my $self = shift; my $msg = shift; print scalar localtime(time) . " INFO: $msg\n"; } package main; my $config = { username => 'blah', password => 'foo', }; unless (@ARGV == 2) { print "Arguments: [phone numbers] [message]\n"; exit 1; } my @stateConfig = ( { name => 'get_homepage', method => 'GET', url => "https://www1.myvodafone.com.au", info => "Getting homepage ...", }, { name => 'login', method => 'POST', url => "https://www1.myvodafone.com.au/userpages", info => "Logging in ...", args => [ login => $config->{username}, password => $config->{password}, TYPE => 'login' ] }, { name => 'get_form', method => 'GET', info => "Getting SMS page ...", url => "https://www1.myvodafone.com.au/userpages/web2txt. +fcgi" }, { name => 'submit_form', method => 'POST', url => "https://www1.myvodafone.com.au/userpages/web2txt. +fcgi", info => "Submitting form ...", args => [ sendmsg => 1, message => $ARGV[1], min => $ARGV[0] ] }, ); my $machine = new URLStateMachine(\@stateConfig); $machine->run;

In reply to Perl2SMS (for Vodafone Australia) by hagus

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.