1 package Net::HTTPS::Any;
5 use base qw( Exporter );
6 use vars qw( @EXPORT_OK );
9 use Net::SSLeay 1.30, qw( get_https post_https make_headers make_form );
11 @EXPORT_OK = qw( https_get https_post );
15 Net::HTTPS::Any - Simple HTTPS client
19 our $VERSION = '0.13';
23 use Net::HTTPS::Any qw(https_get https_post);
25 ( $page, $response, %reply_headers )
27 { 'host' => 'www.fortify.net',
29 'path' => '/sslcheck.html',
30 'args' => { 'field' => 'value' },
31 #'args' => [ 'field'=>'value' ], #order preserved
35 ( $page, $response, %reply_headers )
37 'host' => 'www.google.com',
39 'path' => '/accounts/ServiceLoginAuth',
40 'args' => { 'field' => 'value' },
41 #'args' => [ 'field'=>'value' ], #order preserved
48 This is a wrapper around Net::SSLeay providing a simple interface for the use
49 of Business::OnlinePayment.
51 It used to allow switching between Net::SSLeay and Crypt::SSLeay
52 implementations, but that was obsoleted. If you need to do that, use LWP
53 instead. You can set $Net::HTTPS::SSL_SOCKET_CLASS = "Net::SSL" for
54 Crypt::SSLeay instead of the default Net::SSLeay (since 6.02).
58 =head2 https_get HASHREF | FIELD => VALUE, ...
60 Accepts parameters as either a hashref or a list of fields and values.
72 =item headers (hashref)
74 For example: { 'X-Header1' => 'value', ... }
80 # Defaults to "application/x-www-form-urlencoded" if not specified.
84 CGI arguments, either as a hashref or a listref. In the latter case, ordering
85 is preserved (see L<Tie::IxHash> to do so when passing a hashref).
89 Set true to enable debugging.
93 Returns a list consisting of the page content as a string, the HTTP
94 response code and message (i.e. "200 OK" or "404 Not Found"), and a list of
95 key/value pairs representing the HTTP response headers.
100 my $opts = ref($_[0]) ? shift : { @_ }; #hashref or list
102 # accept a hashref or a list (keep it ordered)
103 my $post_data = {}; # technically get_data, pedant
104 if ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH' ) {
105 $post_data = $opts->{'args'};
106 } elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) {
107 tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} };
111 $opts->{'port'} ||= 443;
112 #$opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
116 if ( ref( $opts->{headers} ) eq "HASH" ) {
117 %headers = %{ $opts->{headers} };
119 $headers{'Host'} ||= $opts->{'host'};
121 my $path = $opts->{'path'};
122 if ( keys %$post_data ) {
125 map { uri_escape($_) . '=' . uri_escape( $post_data->{$_} ) }
129 my $headers = make_headers(%headers);
131 $Net::SSLeay::trace = $opts->{'debug'}
132 if exists $opts->{'debug'} && $opts->{'debug'};
134 no warnings 'uninitialized';
136 my( $res_page, $res_code, @res_headers ) =
137 get_https( $opts->{'host'},
142 #$opts->{"Content-Type"},
145 $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2;
147 return ( $res_page, $res_code, @res_headers );
151 =head2 https_post HASHREF | FIELD => VALUE, ...
153 Accepts parameters as either a hashref or a list of fields and values.
165 =item headers (hashref)
167 For example: { 'X-Header1' => 'value', ... }
171 Defaults to "application/x-www-form-urlencoded" if not specified.
175 CGI arguments, either as a hashref or a listref. In the latter case, ordering
176 is preserved (see L<Tie::IxHash> to do so when passing a hashref).
180 Raw content (overrides args). A simple scalar containing the raw content.
184 Set true to enable debugging in the underlying SSL module.
188 Returns a list consisting of the page content as a string, the HTTP
189 response code and message (i.e. "200 OK" or "404 Not Found"), and a list of
190 key/value pairs representing the HTTP response headers.
195 my $opts = ref($_[0]) ? shift : { @_ }; #hashref or list
197 # accept a hashref or a list (keep it ordered). or a scalar of content.
199 if ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH' ) {
200 $post_data = $opts->{'args'};
201 } elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) {
202 tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} };
205 if ( exists $opts->{'content'} ) {
206 $post_data = $opts->{'content'};
209 $opts->{'port'} ||= 443;
210 $opts->{"Content-Type"} ||= "application/x-www-form-urlencoded";
214 if ( ref( $opts->{headers} ) eq "HASH" ) {
215 %headers = %{ $opts->{headers} };
217 $headers{'Host'} ||= $opts->{'host'};
219 my $headers = make_headers(%headers);
221 $Net::SSLeay::trace = $opts->{'debug'}
222 if exists $opts->{'debug'} && $opts->{'debug'};
224 my $raw_data = ref($post_data) ? make_form(%$post_data) : $post_data;
226 $Net::SSLeay::trace = $opts->{'debug'}
227 if exists $opts->{'debug'} && $opts->{'debug'};
229 no warnings 'uninitialized';
231 my( $res_page, $res_code, @res_headers ) =
232 post_https( $opts->{'host'},
237 $opts->{"Content-Type"},
240 $res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2;
242 return ( $res_page, $res_code, @res_headers );
248 Ivan Kohler, C<< <ivan-net-https-any at freeside.biz> >>
252 Please report any bugs or feature requests to C<bug-net-https-any at rt.cpan.org>, or through
253 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-HTTPS-Any>. I will be notified, and then you'll
254 automatically be notified of progress on your bug as I make changes.
258 You can find documentation for this module with the perldoc command.
260 perldoc Net::HTTPS::Any
262 You can also look for information at:
266 =item * RT: CPAN's request tracker
268 L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-HTTPS-Any>
270 =item * AnnoCPAN: Annotated CPAN documentation
272 L<http://annocpan.org/dist/Net-HTTPS-Any>
276 L<http://cpanratings.perl.org/d/Net-HTTPS-Any>
280 L<http://search.cpan.org/dist/Net-HTTPS-Any>
284 =head1 COPYRIGHT & LICENSE
286 Copyright 2008-2016 Freeside Internet Services, Inc. (http://freeside.biz/)
289 This program is free software; you can redistribute it and/or modify it
290 under the same terms as Perl itself.