M
markandrew
I hae the following VBA script that works fine but I cannot get
HttpWebRequest to do the same job. I get a logon failed error.
Can anyone craft an example from this info?
Sub Get1Report()
Dim doc As Object 'For storing the downloaded report
Dim s$ ' The string sent to the server for retrieving the report
Dim direc$ ' Where to store the downloaded ZIP file (for version=4)
Dim filenumber# ' For writing to the ZIP file
Dim myfile ' For iterating through the ZIP file
Dim sUserName As String
Dim sPassword As String
sUserName = "XXXX"
sPassword = "XXXX"
Set doc = CreateObject("msxml2.ServerXMLHTTP")
doc.Open "POST", "https://www.Host.com/export.jsp", False
doc.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
s = "user=" & sUserName & "&password=" & sPassword &
"&version=4&date=20060103&format=csv&report=ReportName&type=XDS"
' Send the request to the web site
doc.send (s)
' Handle the response
If (Left$(doc.responseText, 2) = "PK") Then ' A ZIP file
On Error Resume Next
direc = "D:\RNGData\download"
MkDir direc
On Error GoTo 0
MkDir direc
filenumber = FreeFile
Open direc & "\file.zip" For Binary Access Write As #filenumber
Put #filenumber, 1, doc.responseBody
Close #filenumber
Set doc = Nothing
End If
Set doc = Nothing
End Sub
HttpWebRequest to do the same job. I get a logon failed error.
Can anyone craft an example from this info?
Sub Get1Report()
Dim doc As Object 'For storing the downloaded report
Dim s$ ' The string sent to the server for retrieving the report
Dim direc$ ' Where to store the downloaded ZIP file (for version=4)
Dim filenumber# ' For writing to the ZIP file
Dim myfile ' For iterating through the ZIP file
Dim sUserName As String
Dim sPassword As String
sUserName = "XXXX"
sPassword = "XXXX"
Set doc = CreateObject("msxml2.ServerXMLHTTP")
doc.Open "POST", "https://www.Host.com/export.jsp", False
doc.setRequestHeader "Content-Type",
"application/x-www-form-urlencoded"
s = "user=" & sUserName & "&password=" & sPassword &
"&version=4&date=20060103&format=csv&report=ReportName&type=XDS"
' Send the request to the web site
doc.send (s)
' Handle the response
If (Left$(doc.responseText, 2) = "PK") Then ' A ZIP file
On Error Resume Next
direc = "D:\RNGData\download"
MkDir direc
On Error GoTo 0
MkDir direc
filenumber = FreeFile
Open direc & "\file.zip" For Binary Access Write As #filenumber
Put #filenumber, 1, doc.responseBody
Close #filenumber
Set doc = Nothing
End If
Set doc = Nothing
End Sub