-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathhttpget.js
34 lines (30 loc) · 940 Bytes
/
httpget.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
var wshell = new ActiveXObject("WScript.Shell");
var xmlhttp = new ActiveXObject("MSXML2.ServerXMLHTTP");
var adodb = new ActiveXObject("ADODB.Stream");
var FSO = new ActiveXObject("Scripting.FileSystemObject");
function http_get(url, is_binary)
{
xmlhttp.open("GET", url);
xmlhttp.setRequestHeader("User-Agent", "curl/7.21.2 (i386-pc-win32) libcurl/7.21.2 OpenSSL/0.9.8o zlib/1.2.5");
xmlhttp.send();
WScript.echo("retrieving " + url);
while (xmlhttp.readyState != 4);
WScript.Sleep(10);
if (xmlhttp.status != 200)
{
WScript.Echo("http get failed: " + xmlhttp.status);
WScript.Quit(2)
};
return is_binary ? xmlhttp.responseBody : xmlhttp.responseText;
};
function save_binary(path, data)
{
adodb.type = 1;
adodb.open();
adodb.write(data);
adodb.saveToFile(path, 2);
};
var base_url = WScript.Arguments(0);
var filename = WScript.Arguments(1);
var bin_data = http_get(base_url, true);
save_binary(filename, bin_data);