Skip to content

Commit a089343

Browse files
authored
Merge pull request #30 from craigberry/master
Add Win32::HttpGetFile
2 parents ff8e050 + beec32d commit a089343

File tree

4 files changed

+458
-3
lines changed

4 files changed

+458
-3
lines changed

Makefile.PL

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ my %param = (
2222
$param{NO_META} = 1 if eval "$ExtUtils::MakeMaker::VERSION" >= 6.10_03;
2323

2424
if ($^O eq 'cygwin') {
25-
$param{LIBS} = ['-L/lib/w32api -lole32 -lversion -luserenv -lnetapi32']
25+
$param{LIBS} = ['-L/lib/w32api -lole32 -lversion -luserenv -lnetapi32 -lwinhttp']
2626
}
2727
else {
28-
$param{LIBS} = ['-luserenv']
28+
$param{LIBS} = ['-luserenv -lwinhttp']
2929
}
3030

3131
my $test_requires = $ExtUtils::MakeMaker::VERSION >= 6.64

Win32.pm

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1305,11 +1305,52 @@ of hex digits with surrounding braces. For example:
13051305
13061306
{09531CF1-D0C7-4860-840C-1C8C8735E2AD}
13071307
1308+
=item Win32::HttpGetFile(URL, FILENAME [, IGNORE_CERT_ERRORS])
1309+
1310+
Uses the WinHttp library to download the file specified by the URL
1311+
parameter to the local file specified by FILENAME. The optional third
1312+
parameter, if true, indicates that certficate errors are to be ignored
1313+
for https connections; please use with caution in a safe environment,
1314+
such as when testing locally using a self-signed certificate.
1315+
1316+
Only http and https protocols are supported. Authentication is not
1317+
supported. The function is not available when building with gcc prior to
1318+
4.8.0 because the WinHttp library is not available.
1319+
1320+
In scalar context returns a boolean success or failure, and in list
1321+
context also returns, in addition to the boolean status, a second
1322+
value containing message text related to the status.
1323+
1324+
If the call fails, C<Win32::GetLastError()> will return a numeric
1325+
error code, which may be a system error, a WinHttp error, or a
1326+
user-defined error composed of 1e9 plus the HTTP status code.
1327+
1328+
Scalar context example:
1329+
1330+
print Win32::GetLastError()
1331+
unless Win32::HttpGetFile('http://example.com/somefile.tar.gz',
1332+
'.\file.tgz');
1333+
1334+
List context example:
1335+
1336+
my ($ok, $msg) = Win32::HttpGetFile('http://example.com/somefile.tar.gz',
1337+
'.\file.tgz');
1338+
if ($ok) {
1339+
print "Success!: $msg\n";
1340+
}
1341+
else {
1342+
print "Failure!: $msg\n";
1343+
my $err = Win32::GetLastError();
1344+
if ($err > 1e9) {
1345+
printf "HTTP status: %d\n", ($err - 1e9);
1346+
}
1347+
}
1348+
13081349
=item Win32::InitiateSystemShutdown
13091350
13101351
(MACHINE, MESSAGE, TIMEOUT, FORCECLOSE, REBOOT)
13111352
1312-
Shutsdown the specified MACHINE, notifying users with the
1353+
Shuts down the specified MACHINE, notifying users with the
13131354
supplied MESSAGE, within the specified TIMEOUT interval. Forces
13141355
closing of all documents without prompting the user if FORCECLOSE is
13151356
true, and reboots the machine if REBOOT is true. This function works

0 commit comments

Comments
 (0)