randallc59 has asked for the wisdom of the Perl Monks concerning the following question:
I need some help adding HTTP Post to an existing code. Need to add the following code: POST /cbridge/xmlhost HTTP/1.1 HOST: 127.0.0.1 Content- length: 357
#!/usr/bin/perl use strict; use IO::Socket; use DBI; use DBD::Oracle; our (@command, $command); our ($socket_success_fl); our $svcpk; my $cable_command; ##$cable_command = ' ##<Transaction id = "12345" wait="1" priority="1"> ##<AddUpdateLocation> ##<LocationId> 8002721493 </LocationId> ##<HeadendCode> 01 </HeadendCode> ##<Address1> 19 Bow Circle </Address1> ##<Address2> Bow Circle Business Ctr Unit 402 </Address2> ##<City> Hilton Head Island</City> ##<State> SC </State> ##<Zip> 29926 </Zip> ##</AddUpdateLocation> ##</Transaction>'; ####$cable_command = $ARGV[0] #### or die "Could not find an argument \n"; print "$cable_command\n"; $socket_success_fl = 'N'; socket_connect(); if ($socket_success_fl =~ /Y/){ process_command(); socket_close(); }elsif ($socket_success_fl =~ /N/){ print "Unable to connect to socket!!....\n"; } sub socket_connect { socket (SH, PF_INET, SOCK_STREAM, getprotobyname('tcp')) || die $! +; my $dest = sockaddr_in (22928, inet_aton('172.17.15.102')); connect (SH, $dest) || die $!; $socket_success_fl = 'Y'; print "Connected to socket\n"; } sub process_command { my $v_param; my $buffer; $v_param = $cable_command; @command = split(/&/,$v_param); foreach $command (@command) { print "$command\n"; if ($command =~ /SVCPK=/ ) { $svcpk = substr($command,6,10); print "svcpk = ", $svcpk, " \n"; } else { print "About to send command\n"; send (SH, "$command\r", 0); print "sent command\n"; print "about to read response buffer\n"; sysread (SH, $buffer, 1000); print "read response buffer\n"; print "response = ", $buffer, " \n"; } } } sub socket_close{ close(SH); print "Socket closed \n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Add HTTP Post For Socket Connection
by flexvault (Monsignor) on Nov 07, 2012 at 14:22 UTC | |
|
Re: Add HTTP Post For Socket Connection
by flexvault (Monsignor) on Nov 07, 2012 at 21:11 UTC |