line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::HTTPS::Any; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
47026
|
use warnings; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
92
|
|
4
|
3
|
|
|
3
|
|
11
|
use strict; |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
65
|
|
5
|
3
|
|
|
3
|
|
11
|
use base qw( Exporter ); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
261
|
|
6
|
3
|
|
|
3
|
|
13
|
use vars qw( @EXPORT_OK ); |
|
3
|
|
|
|
|
4
|
|
|
3
|
|
|
|
|
147
|
|
7
|
3
|
|
|
3
|
|
1352
|
use URI::Escape; |
|
3
|
|
|
|
|
3447
|
|
|
3
|
|
|
|
|
191
|
|
8
|
3
|
|
|
3
|
|
1441
|
use Tie::IxHash; |
|
3
|
|
|
|
|
10804
|
|
|
3
|
|
|
|
|
99
|
|
9
|
3
|
|
|
3
|
|
1849
|
use Net::SSLeay 1.30, qw( get_https post_https make_headers make_form ); |
|
3
|
|
|
|
|
39049
|
|
|
3
|
|
|
|
|
3816
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
@EXPORT_OK = qw( https_get https_post ); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Net::HTTPS::Any - Simple HTTPS client |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.12'; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 SYNOPSIS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
use Net::HTTPS::Any qw(https_get https_post); |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
( $page, $response, %reply_headers ) |
26
|
|
|
|
|
|
|
= https_get( |
27
|
|
|
|
|
|
|
{ 'host' => 'www.fortify.net', |
28
|
|
|
|
|
|
|
'port' => 443, |
29
|
|
|
|
|
|
|
'path' => '/sslcheck.html', |
30
|
|
|
|
|
|
|
'args' => { 'field' => 'value' }, |
31
|
|
|
|
|
|
|
#'args' => [ 'field'=>'value' ], #order preserved |
32
|
|
|
|
|
|
|
}, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
( $page, $response, %reply_headers ) |
36
|
|
|
|
|
|
|
= https_post( |
37
|
|
|
|
|
|
|
'host' => 'www.google.com', |
38
|
|
|
|
|
|
|
'port' => 443, |
39
|
|
|
|
|
|
|
'path' => '/accounts/ServiceLoginAuth', |
40
|
|
|
|
|
|
|
'args' => { 'field' => 'value' }, |
41
|
|
|
|
|
|
|
#'args' => [ 'field'=>'value' ], #order preserved |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
#... |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 DESCRIPTION |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This is a wrapper around Net::SSLeay providing a simple interface for the use |
49
|
|
|
|
|
|
|
of Business::OnlinePayment. |
50
|
|
|
|
|
|
|
|
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). |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head1 FUNCTIONS |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 https_get HASHREF | FIELD => VALUE, ... |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Accepts parameters as either a hashref or a list of fields and values. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
Parameters are: |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=over 4 |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=item host |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item port |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=item path |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=item headers (hashref) |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
For example: { 'X-Header1' => 'value', ... } |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
# =item Content-Type |
79
|
|
|
|
|
|
|
# |
80
|
|
|
|
|
|
|
# Defaults to "application/x-www-form-urlencoded" if not specified. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=item args |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
CGI arguments, either as a hashref or a listref. In the latter case, ordering |
85
|
|
|
|
|
|
|
is preserved (see L to do so when passing a hashref). |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item debug |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Set true to enable debugging. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=back |
92
|
|
|
|
|
|
|
|
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. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub https_get { |
100
|
2
|
50
|
|
2
|
1
|
743
|
my $opts = ref($_[0]) ? shift : { @_ }; #hashref or list |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
# accept a hashref or a list (keep it ordered) |
103
|
2
|
|
|
|
|
5
|
my $post_data = {}; # technically get_data, pedant |
104
|
2
|
50
|
33
|
|
|
19
|
if ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH' ) { |
|
|
50
|
33
|
|
|
|
|
105
|
0
|
|
|
|
|
0
|
$post_data = $opts->{'args'}; |
106
|
|
|
|
|
|
|
} elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) { |
107
|
0
|
|
|
|
|
0
|
tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} }; |
|
0
|
|
|
|
|
0
|
|
108
|
0
|
|
|
|
|
0
|
$post_data = \%hash; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
2
|
|
50
|
|
|
8
|
$opts->{'port'} ||= 443; |
112
|
|
|
|
|
|
|
#$opts->{"Content-Type"} ||= "application/x-www-form-urlencoded"; |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
### XXX referer!!! |
115
|
2
|
|
|
|
|
5
|
my %headers = (); |
116
|
2
|
50
|
|
|
|
6
|
if ( ref( $opts->{headers} ) eq "HASH" ) { |
117
|
0
|
|
|
|
|
0
|
%headers = %{ $opts->{headers} }; |
|
0
|
|
|
|
|
0
|
|
118
|
|
|
|
|
|
|
} |
119
|
2
|
|
33
|
|
|
15
|
$headers{'Host'} ||= $opts->{'host'}; |
120
|
|
|
|
|
|
|
|
121
|
2
|
|
|
|
|
4
|
my $path = $opts->{'path'}; |
122
|
2
|
50
|
|
|
|
8
|
if ( keys %$post_data ) { |
123
|
|
|
|
|
|
|
$path .= '?' |
124
|
|
|
|
|
|
|
. join( ';', |
125
|
0
|
|
|
|
|
0
|
map { uri_escape($_) . '=' . uri_escape( $post_data->{$_} ) } |
|
0
|
|
|
|
|
0
|
|
126
|
|
|
|
|
|
|
keys %$post_data ); |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
2
|
|
|
|
|
32
|
my $headers = make_headers(%headers); |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
$Net::SSLeay::trace = $opts->{'debug'} |
132
|
2
|
0
|
33
|
|
|
603
|
if exists $opts->{'debug'} && $opts->{'debug'}; |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
my( $res_page, $res_code, @res_headers ) = |
135
|
|
|
|
|
|
|
get_https( $opts->{'host'}, |
136
|
2
|
|
|
|
|
25
|
$opts->{'port'}, |
137
|
|
|
|
|
|
|
$path, |
138
|
|
|
|
|
|
|
$headers, |
139
|
|
|
|
|
|
|
#"", |
140
|
|
|
|
|
|
|
#$opts->{"Content-Type"}, |
141
|
|
|
|
|
|
|
); |
142
|
|
|
|
|
|
|
|
143
|
2
|
50
|
|
|
|
1321363
|
$res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2; |
144
|
|
|
|
|
|
|
|
145
|
2
|
|
|
|
|
38
|
return ( $res_page, $res_code, @res_headers ); |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 https_post HASHREF | FIELD => VALUE, ... |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Accepts parameters as either a hashref or a list of fields and values. |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
Parameters are: |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
=over 4 |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item host |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=item port |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=item path |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=item headers (hashref) |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
For example: { 'X-Header1' => 'value', ... } |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=item Content-Type |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Defaults to "application/x-www-form-urlencoded" if not specified. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=item args |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
CGI arguments, either as a hashref or a listref. In the latter case, ordering |
174
|
|
|
|
|
|
|
is preserved (see L to do so when passing a hashref). |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item content |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
Raw content (overrides args). A simple scalar containing the raw content. |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item debug |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Set true to enable debugging in the underlying SSL module. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=back |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Returns a list consisting of the page content as a string, the HTTP |
187
|
|
|
|
|
|
|
response code and message (i.e. "200 OK" or "404 Not Found"), and a list of |
188
|
|
|
|
|
|
|
key/value pairs representing the HTTP response headers. |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
=cut |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub https_post { |
193
|
2
|
50
|
|
2
|
1
|
1033
|
my $opts = ref($_[0]) ? shift : { @_ }; #hashref or list |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
# accept a hashref or a list (keep it ordered). or a scalar of content. |
196
|
2
|
|
|
|
|
4
|
my $post_data = ''; |
197
|
2
|
50
|
33
|
|
|
18
|
if ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'HASH' ) { |
|
|
0
|
0
|
|
|
|
|
198
|
2
|
|
|
|
|
5
|
$post_data = $opts->{'args'}; |
199
|
|
|
|
|
|
|
} elsif ( exists($opts->{'args'}) && ref($opts->{'args'}) eq 'ARRAY' ) { |
200
|
0
|
|
|
|
|
0
|
tie my %hash, 'Tie::IxHash', @{ $opts->{'args'} }; |
|
0
|
|
|
|
|
0
|
|
201
|
0
|
|
|
|
|
0
|
$post_data = \%hash; |
202
|
|
|
|
|
|
|
} |
203
|
2
|
50
|
|
|
|
8
|
if ( exists $opts->{'content'} ) { |
204
|
0
|
|
|
|
|
0
|
$post_data = $opts->{'content'}; |
205
|
|
|
|
|
|
|
} |
206
|
|
|
|
|
|
|
|
207
|
2
|
|
50
|
|
|
7
|
$opts->{'port'} ||= 443; |
208
|
2
|
|
50
|
|
|
10
|
$opts->{"Content-Type"} ||= "application/x-www-form-urlencoded"; |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
### XXX referer!!! |
211
|
2
|
|
|
|
|
3
|
my %headers; |
212
|
2
|
50
|
|
|
|
6
|
if ( ref( $opts->{headers} ) eq "HASH" ) { |
213
|
0
|
|
|
|
|
0
|
%headers = %{ $opts->{headers} }; |
|
0
|
|
|
|
|
0
|
|
214
|
|
|
|
|
|
|
} |
215
|
2
|
|
33
|
|
|
10
|
$headers{'Host'} ||= $opts->{'host'}; |
216
|
|
|
|
|
|
|
|
217
|
2
|
|
|
|
|
36
|
my $headers = make_headers(%headers); |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
$Net::SSLeay::trace = $opts->{'debug'} |
220
|
2
|
0
|
33
|
|
|
572
|
if exists $opts->{'debug'} && $opts->{'debug'}; |
221
|
|
|
|
|
|
|
|
222
|
2
|
50
|
|
|
|
68
|
my $raw_data = ref($post_data) ? make_form(%$post_data) : $post_data; |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
$Net::SSLeay::trace = $opts->{'debug'} |
225
|
2
|
0
|
33
|
|
|
326
|
if exists $opts->{'debug'} && $opts->{'debug'}; |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
my( $res_page, $res_code, @res_headers ) = |
228
|
|
|
|
|
|
|
post_https( $opts->{'host'}, |
229
|
|
|
|
|
|
|
$opts->{'port'}, |
230
|
|
|
|
|
|
|
$opts->{'path'}, |
231
|
|
|
|
|
|
|
$headers, |
232
|
|
|
|
|
|
|
$raw_data, |
233
|
2
|
|
|
|
|
24
|
$opts->{"Content-Type"}, |
234
|
|
|
|
|
|
|
); |
235
|
|
|
|
|
|
|
|
236
|
2
|
50
|
|
|
|
184452
|
$res_code =~ /^(HTTP\S+ )?(.*)/ and $res_code = $2; |
237
|
|
|
|
|
|
|
|
238
|
2
|
|
|
|
|
37
|
return ( $res_page, $res_code, @res_headers ); |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
} |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 AUTHOR |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
Ivan Kohler, C<< >> |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
=head1 BUGS |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
249
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
250
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
=head1 SUPPORT |
253
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
255
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
perldoc Net::HTTPS::Any |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
You can also look for information at: |
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
=over 4 |
261
|
|
|
|
|
|
|
|
262
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
263
|
|
|
|
|
|
|
|
264
|
|
|
|
|
|
|
L |
265
|
|
|
|
|
|
|
|
266
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
267
|
|
|
|
|
|
|
|
268
|
|
|
|
|
|
|
L |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=item * CPAN Ratings |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
L |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
=item * Search CPAN |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
L |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
=back |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 COPYRIGHT & LICENSE |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Copyright 2008-2016 Freeside Internet Services, Inc. (http://freeside.biz/) |
283
|
|
|
|
|
|
|
All rights reserved. |
284
|
|
|
|
|
|
|
|
285
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
286
|
|
|
|
|
|
|
under the same terms as Perl itself. |
287
|
|
|
|
|
|
|
|
288
|
|
|
|
|
|
|
=cut |
289
|
|
|
|
|
|
|
|
290
|
|
|
|
|
|
|
1; |