You can use the Toolkit to do this. Using Immed, for example:
Set downloadObj =
SharedObjects("com.GWMicro.GWToolkit.Download").NewDownload()
downloadObj.URL = "http://www.gwmicro.com"
downloadObj.FileName = "robots.txt"
downloadObj.GetFile()
To see the results:
print downloadObj.ReturnString()
If you want to roll your own, here's an example that supports
authentication, along with proxy access, and a custom user agent string:
Function GetData(strUrl, strUser, strPass, strProxy, strProxyUser,
strProxyPass, strUA)
Dim winhttp, attempts, done
' Init
Set winhttp = Nothing
GetData = -1
' Begin
Set winhttp = CreateObject("WinHttp.WinHttpRequest.5.1")
If Not winhttp Is Nothing Then
LoadClassInformation
winhttp.SetTimeouts 30000, 60000, 120000, 60000
If strProxy <> "" Then
winhttp.SetProxy 2, strProxy
End If
winhttp.Open "GET", strUrl, False
winhttp.Option(0) = strUA ' User Agent string
winhttp.Option(4) = 13056 ' Ignore all SSL errors
Do
attempts = attempts + 1
On Error Resume Next
winhttp.Send()
If Err.Number <> 0 Then
MessageBox Hex(Err.Number) & ": " & Err.Description,
vbOkOnly + vbCritical, "HTTP Error"
Exit Do
End If
On Error Goto 0
Select Case winhttp.Status
Case "200"
done = True
Case "401"
winhttp.SetCredentials strUser, strPass, 0
Case "407"
If strProxyUser <> "" And strProxyPass <> "" Then
winhttp.SetCredentials strProxyUser,
strProxyPass HTTPREQUEST_SETCREDENTIALS_FOR_PROXY
End If
Case Else
done = True
End Select
Loop While Not done And (attempts < 3)
GetData = winhttp.ResponseText
End If
Set winhttp = Nothing
End Function
Aaron
On 9/18/2012 7:56 PM, RicksPlace wrote:
Hi:
I want to access the Yahoo Finance Data File which is a csv file.
To download it I need to issue a http request.
Does anyone have code that downloads a file from the internet using
http orsomething similar?
Rick USA
--
Aaron Smith
Web Development * App Development * Product Support Specialist
GW Micro, Inc. * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * gwmicro.com
To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.