1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| Function LoginAndDownload2(LoginLink As String, Request As Variant, DownloadLink As String, file As String)
Dim XMLHTTP As Object, tempfile As Long, Response() As Byte
Set XMLHTTP = CreateObject("MSXML2.XMLHTTP")
XMLHTTP.Open "POST", LoginLink, False
XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHTTP.Send Request
Do While XMLHTTP.READYSTATE <> 4
DoEvents
Loop
XMLHTTP.Open "POST", DownloadLink, False
XMLHTTP.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
XMLHTTP.Send Request
Do While XMLHTTP.READYSTATE <> 4
DoEvents
Loop
'Response = XMLHTTP.responseBody
tempfile = FreeFile
If Dir(file) <> "" Then Kill file
Open file For Binary As #tempfile
Put #tempfile, , Response
Close #tempfile
Set XMLHTTP = Nothing
End Function |
Partager