- import HTTP::Request::Common qw(POST);
-
- my $url = 'https://' . $opts->{'host'};
- $url .= ':' . $opts->{'port'}
- unless $opts->{'port'} == 443;
- $url .= $opts->{'path'};
-
- my $ua = new LWP::UserAgent;
- foreach my $hdr ( keys %headers ) {
- $ua->default_header( $hdr => $headers{$hdr} );
- }
-
- $ENV{HTTPS_DEBUG} = $opts->{'debug'} if exists $opts->{'debug'};
-
- my $res;
- if ( ref($post_data) ) {
- $res = $ua->request( POST( $url, [%$post_data] ) );
- }
- else {
- my $req = new HTTP::Request( 'POST' => $url );
- $req->content_type( $opts->{"Content-Type"} );
- $req->content($post_data);
- $res = $ua->request($req);
- }
-
- my @res_headers = map { $_ => $res->header($_) }
- $res->header_field_names;
-
- return ( $res->content, $res->code. ' '. $res->message, @res_headers );
-
- } else {
- die "unknown SSL module $ssl_module";
- }