+on error resume next\r
+\r
if WScript.Arguments.Count < 2 then\r
WScript.Echo "usage: http-get.vbs source-url dest-file"\r
WScript.Quit 1\r
\r
dim http, source_data\r
set http = CreateObject("WinHttp.WinHttpRequest.5.1")\r
+\r
+ Err.Clear\r
http.Open "GET", source_url, false\r
http.Send\r
\r
- if http.Status = 200 then\r
- dim dest_stream\r
- set dest_stream = CreateObject("ADODB.Stream")\r
+ if Err.Number = 0 then\r
+ if http.Status = 200 then\r
+ dim dest_stream\r
+ set dest_stream = CreateObject("ADODB.Stream")\r
\r
- dest_stream.Type = 1 ' adTypeBinary\r
- dest_stream.Open\r
- dest_stream.Write http.ResponseBody\r
- dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite\r
-\r
- set dest_stream = nothing\r
+ Err.Clear\r
+ dest_stream.Type = 1 ' adTypeBinary\r
+ dest_stream.Open\r
+ dest_stream.Write http.ResponseBody\r
+ dest_stream.SaveToFile dest_filename, 2 ' adSaveCreateOverWrite\r
+ if Err.Number <> 0 then\r
+ WScript.Echo "Error " + CStr(Err.Number) + " when writing " + dest_filename + ":"\r
+ WScript.Echo Err.Description\r
+ WScript.Quit 1\r
+ end if\r
+ else\r
+ WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url\r
+ WScript.Quit 1\r
+ end if\r
else\r
- WScript.Echo CStr(http.Status) + " " + http.StatusText + " when fetching " + source_url\r
+ WScript.Echo "Error " + CStr(Err.Number) + " when fetching " + source_url + ":"\r
+ WScript.Echo Err.Description\r
WScript.Quit 1\r
end if\r
-\r
- set http = nothing\r
end if\r