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, ...
Dim oHttp, sUrl, sSavePath, oStream
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.20 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