View Single Post
 
Old 10-20-2013, 10:02 AM
Catalin.B Catalin.B is offline Windows Vista Office 2010 32bit
Expert
 
Join Date: May 2011
Location: Iaşi, Romānia
Posts: 386
Catalin.B is on a distinguished road
Default

Well, after some attempts, still no valid file.
The code: (in 2 versions)
Code:
Sub DownloadFile()

Dim myURL As String
myURL = "http://horseracebase.com/excellcards.php"

Dim WinHttpReq As Object


Set WinHttpReq = CreateObject("Microsoft.XMLHTTP")
WinHttpReq.Open "POST", myURL, False, ".........", "........."
WinHttpReq.Send

myURL = WinHttpReq.responseBody
If WinHttpReq.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write WinHttpReq.responseBody
    oStream.SaveToFile ThisWorkbook.Path & "\cards " & Format(Time, "hh-mm") & ".xls", 2
    oStream.Close
End If

End Sub
Sub DownloadFile2()

Dim myURL As String
myURL = "http://horseracebase.com/excellcards.php"

Dim req As Object
Dim user As String, pass As String
user = "........."
pass = "........."
credentials = "username=" & user & "&password=" & pass



Set req = CreateObject("WinHttp.WinHttpRequest.5.1")
req.SetAutoLogonPolicy 0

req.Open "POST", myURL, False
req.SetRequestHeader "Content-Type", "application/x-www-form-urlencoded"
req.Send credentials

myURL = req.responseBody
If req.Status = 200 Then
    Set oStream = CreateObject("ADODB.Stream")
    oStream.Open
    oStream.Type = 1
    oStream.Write req.responseBody
    oStream.SaveToFile "E:\cards.xls", 2 ' 1 = no overwrite, 2 = overwrite
    oStream.Close
End If

End Sub
Both codes downloads the file but the problem is that the code is not actually logging in, the cards file downloaded has this message inside:
" <p class=standard>You must hold a valid <a href='index.php'>HorseRaceBase</a> membership to access this feature. <a href='subscribe.php'>Sign up for a free trial now</a></p>

Can you point to the source of this error? I have to say i could not found the error, i used Fiddler to analyze browsing session, no result...
Reply With Quote