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 35 36 37
| Public Function DownloadHTTP(ByVal URL As String, ByVal Destination As String) As Boolean
'http://blog.developpez.com/philben/p...access/qr_code
On Error GoTo catch
Dim oWinHTTP As Object
Dim fic As Integer
Dim buffer() As Byte
Set oWinHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")
oWinHTTP.Open "GET", URL, False
oWinHTTP.send
If oWinHTTP.Status = 200 Then
fic = FreeFile
Open Destination For Binary Lock Read Write As #fic
buffer = oWinHTTP.ResponseBody
Put #fic, , buffer
Close #fic
DownloadHTTP = True
Else
MsgBox "Statut retourné par le service : " & oWinHTTP.Status & vbCrLf & _
"Description : " & oWinHTTP.StatusText, vbExclamation, "DownloadHTTP()..."
End If
finally:
Erase buffer
Set oWinHTTP = Nothing
Exit Function
catch:
MsgBox "Erreur n°" & Err.Number & vbCrLf & "Description : " & Err.Description, vbExclamation, "DownloadHTTP()..."
Close 'ferme tous les descripteurs ouverts
Resume finally
End Function |
Partager