#!/usr/bin/perl use strict; use Time::HiRes qw( usleep time gettimeofday tv_interval ); use LWP; use HTTP::Request::Common; use URI::Escape; use CGI qw/:standard *table start_ul use_named_parameters/; # load standard CGI routines use CGI::Carp qw /fatalsToBrowser/; use CGI::Pretty ":standard"; print "Content-Type: text/html\r\n\r\n"; print "\n"; print "\n"; print "\n"; print "\n"; print "
\n"; my @SNSresponse; sSendToSNS('192.168.0.8','80','SNSphone2e.pl','EX=RUT&LOGIN=test&PASSWORD=test&FLOORID=TEST&HPNUM=1234','me',\@SNSresponse); print "
\n"; print "\n"; exit; sub sSendToSNS { my $ip = $_[0]; my $port = $_[1]; my $script = $_[2]; my $msg = $_[3]; my $caller = $_[4]; my $retarray = $_[5]; my $retval = 0; my $response; if ( my $ua = LWP::UserAgent->new ) { $ua->timeout(30); my $request = POST( "http://$ip/scripts/$script", Content_Type => 'form_data', Content => [ message => [$msg] ]); # 20030317 gk - this methodology sends a properly formatted POST with key/value pairs. # it does not work because it does not ADD to the POST but replaces it # need to fix this $response = $ua->request($request); print "\$ip=|$ip|, \$script=|$script|, \$msg=|$msg|
\n"; if ( $response->is_success ) { my $returnmsg = $response->content; if ( grep(/\%\%DATA RECEIVED/,$returnmsg) ) { my @returnline = split(/\n/,$returnmsg); foreach my $line ( @returnline ) { print "\$line=|$line|
\n"; if ( substr($line,0,4) eq 'SNS:' ) { push(@$retarray,$line); } # end if ( substr($line,0,4) eq 'SNS:' ) } # end foreach my $line ( @returnline ) } # end if ( grep(/\%\%DATA RECEIVED/,$returnmsg) ) } else { print "failed response $!
\n"; } # end if ( $response->is_success ) } else { print "failed ua $!
\n"; } # end if ( my $ua = LWP::UserAgent->new ) return; } #### [root@localhost cgi-bin]# perl kk.pl Content-Type: text/html
$ip=|192.168.0.8|, $script=|SNSphone2e.pl|, $msg=|EX=RUT&LOGIN=test&PASSWORD=test&FLOORID=TEST&HPNUM=1234|
$line=||
$line=||
$line=||
$line=|SNS:%%DATA RECEIVED|
$line=|SNS:ACK=|
$line=|SNS:HPNUM=1234&USERTYPES=As,Bs|
$line=||
$line=||
$line=|TIME=2007-05-02 17:50:05.114979&ETIME=1178149805.114979|
[root@localhost cgi-bin]# ##
## $ip=|192.168.0.8|, $script=|SNSphone2e.pl|, $msg=|EX=RUT&LOGIN=testcashier&PASSWORD=testcashier&FLOORID=TEST&HPNUM=1234| failed response Permission denied