Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
#!/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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2024-04-18 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found