I'm trying to access a https page to download a PDF file that is returned by the server with the following url format: https://xxx/clApp?xxxxx=makeReport&xxxx&endDate=31aug18&beginDate=01aug18
I started using httpreq but have no idea how to deal with javascript page. If i copy this link to a web browser it directly opens the pdf viewer.
Thanks for your Help.
Code:
<code>Sub SavePdfFromURL()
Dim fileUrl As String
Dim filePath As String
Dim WHTTP As Object
fileUrl = "https://xx/clApp?xx&xxEndDate=31aug18&beginDate=01aug18"
filePath = "C:\Users\xxx\Desktop\duty.pdf"
Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1")
WHTTP.Open "GET", fileUrl, False
WHTTP.setRequestHeader "Content-Type", "application/pdf"
WHTTP.send
If WHTTP.Status = 200 Then
Set oStream = CreateObject("ADODB.Stream")
oStream.Open
oStream.Type = 1
oStream.Write WHTTP.responsebody
oStream.SaveToFile filePath, 1
oStream.Close
End If
MsgBox "File has been saved!", vbInformation, "Success"</code>
Thanks for your Help.