Skip to content

Instantly share code, notes, and snippets.

@brettfreer
Created May 26, 2016 00:09
Show Gist options
  • Save brettfreer/86cb691fca26c647e88064243ca1054f to your computer and use it in GitHub Desktop.
Save brettfreer/86cb691fca26c647e88064243ca1054f to your computer and use it in GitHub Desktop.
Example perl script showing http(s) post of a cXML document
#!/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