Skip to content

Instantly share code, notes, and snippets.

@brettfreer
Created May 26, 2016 00:12
Show Gist options
  • Save brettfreer/348a7ba09ec2086e8376411601d53061 to your computer and use it in GitHub Desktop.
Save brettfreer/348a7ba09ec2086e8376411601d53061 to your computer and use it in GitHub Desktop.
Example showing perl multipart http(s) post
#!/usr/bin/perl -w
use strict;
use LWP::UserAgent;
my $url = 'https://someurl.com/einvoice.dll';
my $filename = $ARGV[0];
my $sid = "username";
my $spwd = "password";
&usage unless ($filename);
&main();
sub main()
{
my $ua = LWP::UserAgent->new();
my $res = $ua->post(
$url,
Content_Type => 'multipart/form-data',
Content => [
'supplier_id' => $sid,
'supplier_pwd' => $spwd,
'invoice_xml' => [$filename],
]
);
my $resp = $res->as_string;
print $resp;
}
sub usage
{
print "usage: perl-post-multipart.pl filename\n\n" ;
exit 1
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment