Created
May 26, 2016 00:09
-
-
Save brettfreer/86cb691fca26c647e88064243ca1054f to your computer and use it in GitHub Desktop.
Example perl script showing http(s) post of a cXML document
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
use strict; | |
use LWP::UserAgent; | |
use HTTP::Request::Common qw(POST); | |
use Net::SSL; | |
use LWP::Protocol::https; | |
use URI::https; | |
my $url = 'https://someurl.com/SubmitCXML'; | |
my $filename = $ARGV[0]; | |
&usage unless ($filename); | |
&main(); | |
sub main() | |
{ | |
my $ua = LWP::UserAgent->new(); | |
my $req = HTTP::Request->new( POST => $url ); | |
open(MYINPUTFILE, $filename); | |
my $holdTerminator = $/; | |
undef $/; | |
my $buf = <MYINPUTFILE>; | |
$/ = $holdTerminator; | |
close(MYINPUTFILE); | |
$req->content_type('text/xml'); | |
$req->content($buf); | |
my $res = $ua->request($req); | |
my $resp = $res->as_string; | |
print $resp; | |
} | |
sub usage | |
{ | |
print "usage: perl-post-xml.pl filename\n\n" ; | |
exit 1 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment