elzemeyer has asked for the wisdom of the Perl Monks concerning the following question:

Monks:
utilzing LWP to post to messaging.sprintpcs.com/sms
i came up with this code.
why will the message not go through. please add your own sprint phone number
#!/usr/bin/perl -w use strict; require LWP::Protocol::http; require LWP::UserAgent; use LWP::Simple; my $sprint_url = "http://www.messaging.sprintpcs.com/sms/check_message +_syntax.html"; my $pcs_number = "##########"; my $callback_number = "##########"; my $message = "I am a sms phone"; my $email_address = ""; my ($s,$c,$h) = &GetURL( $sprint_url, $pcs_number, $callback_number, $message, $email_address ); print $c, "\n"; sub GetURL { my ($sprint_url,$pcs,$back,$msg,$e) = @_; print "Getting $sprint_url ...\n"; print "$back \t $msg \n"; my $ua = new LWP::UserAgent; # Faking from Netscape 4.05, not perl $ua->agent('Mozilla/4.05 [en] (WinNT; I)'); $ua->proxy(['http', 'ftp'], 'http://hqifwdu1:8080/'); my $testURL = new URI::URL("$sprint_url"); #$request = new HTTP::Request('GET', $testURL); my $request = new HTTP::Request('POST', $testURL); $request->content_type('application/x-www-form-urlencoded'); my $formfields =qq( mobilenum=$pcs callbacknum=$back message= $msg + ack_add= "$e"); print "$formfields \n"; $request->content($formfields); my $response = $ua->request($request, undef, undef); my $str = $response->as_string; my $cont = $response->content; my $head = $response->headers_as_string(); return ($str,$cont,$head); }

Replies are listed 'Best First'.
Re: send message to sprint PCS through their site
by shotgunefx (Parson) on Aug 20, 2001 at 23:16 UTC
    Here's the code I use to post on my watchdog system to report problems to my PCS phone.
    use LWP::UserAgent; use HTTP::Request::Common qw(POST); sub message_PCS{ my $msg = $_[0]; $ua = LWP::UserAgent->new(); my $req = POST 'http://www.messaging.sprintpcs.com/sms/check_m +essage_syntax.html', [ mobilenum => '**********', message => $message , call +backnum => '**********', ack_add =>'redalert\@somehwere.com'] $content = $ua->request($req)->as_string; }


    Update: Added the modules the sub uses.
    UPDATE 04-16-2002 Sprint site has changed. See code update in reply to this message by metlhed_

    -Lee

    "To be civilized is to deny one's nature."
      Sprint has changed their site around a bit and that code will no longer work. Here is an updated version:
      #!/usr/bin/perl -w use strict; use LWP::UserAgent; use HTTP::Request::Common qw(POST); &send_message ('1234567890', 'this is the message', 'metlhed'); sub send_message { my ($phone_num, $message, $call_back) = @_; my ($ua, $req, $content); $ua = LWP::UserAgent->new (); $req = POST 'http://www.messaging.sprintpcs.com/smswmgr/BMG/sendme +ssage.jsp', [ device => 'phone', phoneMin => $phone_num, msg => $message, callBackMin => $call_back, copyEsclateRadio => 'NO VALUE', ]; $content = $ua->request ($req)->as_string; }
        Thanks. I ran into that about a month ago when one a server problem arose and I didn't get notified. I neglected to put the updated version here. Now I have it send me a msg every few days to ping me.

        -Lee

        "To be civilized is to deny one's nature."
Re: send message to sprint PCS through their site
by Cine (Friar) on Aug 20, 2001 at 23:09 UTC
    Problem is this line: my $formfields =qq( mobilenum=$pcs callbacknum=$back message= $msg ack_add= "$e");
    It has to URL encoded, that is what you are telling the line above.
    Try setting $request->content("mobilenum=xxxxxxx&callbacknum=xxxxxxx&message=Hejsa&ack_add=me");

    T I M T O W T D I
      Yeah! Thats what I was trying to say. He was sending it to the server telling the server that the request was urlencoded but the message he was actually sending was not urlencoded thus the server was not recognizing the request. Right? I am actually catching on to this stuff ;)...

      ----------
      - Jim

Re: send message to sprint PCS through their site
by snafu (Chaplain) on Aug 20, 2001 at 23:00 UTC
    Well, I admit I am new to this module and am not even remotely close to being a CGI guru but I noticed something that *might* cause a problem and that is only if the LWP doesn't actually do this for you and that is that you are sending the information to the server as urlencoded. If you aren't actually urlencoding I would think that the server wouldn't understand the messages you posting to it.

    $request->content_type('application/x-www-form-urlencoded');

    I don't have time right now to check this further because I am at work. At a glance this popped out at me. Anyone else?

    ----------
    - Jim

      The standard is to send it as 'application/x-www-form-urlencoded' when not specified, which it isnt in the html code, so that part is correct enough.

      T I M T O W T D I
Re: send message to sprint PCS through their site
by scain (Curate) on Aug 20, 2001 at 22:27 UTC
    Are you getting any sort of error message that might make it easier to understand what is happening? Post those too.

    Scott

      Hey:
      the responce that I recieve from the web site is
      is below
      but the issue is with the way the message variable is posted
      the source of the site reveals the input area as

      textarea wrap:VIRTUAL

      check out the site messaging.sprintpcs.com/sms

      <CODE> The message could not be submitted for delivery because:

      There is no callback number or message.
      If possible, please make the necessary changes and try to send your message again.

      <CODE> if I include a callback number it produces no error and
      sends the callback number to the phone
      BUT it hasn't sent the message under any testing circumstances
      I assume this is something to do with the different type of input

        Have you tried a different message, something shorter perhaps? or try embedding "\n"s in the message. I suspect it wants a messge that will easily fit on the phone's display.

        Scott

Re: send message to sprint PCS through their site
by diotalevi (Canon) on May 17, 2004 at 13:45 UTC

    echo 'message' | mailx xxxxxxxxxx@messaging.sprintpcs.com is loads easier.