How to save a binary file (image) from url address

The following script allows to download and save a binary file from specific url address. The Microsoft HTTP request technology is used in this script in order to download the binary file from url address. The Ado technology is used for saving the contents of the file to disk. Both technologies are launched by the CreateObject method.
The example of download and save of image generated by Web camera:
The script can be included into the application for example into the objects PmTimer, PmKey, ...
VBScriptSelect and copy to clipboard

Dim oHttp, oStream, sUrl, sSavePath
sSavePath = Pm.DiscGetPath("#appres:") & "MyPicture.jpg"
sUrl = ""

Set oHttp = CreateObject("Microsoft.XMLHTTP")

oHttp.Open "GET", sUrl, false, "username", "password"  'username and password only if proxy server
oHttp.setRequestHeader "Content-Type", "image/multipart"
If oHttp.readyState = 4 And oHttp.status = 200 Then
  Set oStream = CreateObject("")
  oStream.type = 1  '1=adTypeBinary
  oStream.write oHttp.responseBody
  oStream.savetofile sSavePath, 2  '2=adSaveCreateOverWrite, 1=adSaveCreateNotExist
  Set oStream = Nothing
End If
Set oHttp = Nothing
PROMOTIC 8.3.30 SCADA system documentation - MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice