[AccessD] A2003:Connect to a text file at a web address

MartyConnelly martyconnelly at shaw.ca
Mon Dec 20 01:37:13 CST 2004


Oh well in that case try the xmlhttp request object

I think you may have to write a couple of varieties of Create Object 
depending on the OS
and installed version of XML, if you have IE 5.5 or 6.0 installed you 
have the XML parser.
I think  CreateObject("Microsoft.XMLHTTP") should work through all 
versions of MS XML 2.0 through 4.0
but I can't remember.

'This code fires off request to specified WEB page
'returns html, asp, xml, or text page in text string then sent to file 
on disk
'Makes use of the XMLHTTPRequest object contained in msxml.dll.
'Check off Reference to MSXML Version 2.0 3.0
' I am using latest Version of IE6
' should also work with IE5.0 MSXML ver 2.0,2.6, 3.0 etc

'GrabTextFileFromWebSite 
"http://www5.brinkster.com/mconnelly/GenericDB/ordersSubFormform.txt"

Public Sub GrabTextFileFromWebSite(strMyURL As String)
  
     'Dim oHttp As Object
     Dim oHttp As New MSXML2.XMLHTTP40
     Dim strFileName As String
     Dim intfile As Integer
     Dim bData() As Byte
    
    'make use of the XMLHTTPRequest object contained in msxml.dll
    ' Set oHttp = CreateObject("MSXML2.XMLHTTP40")
    'Set oHttp = GetObject("MSXML2.XMLHTTP30")
    'oHttp.setRequestHeader "Content-Type", 
"application/x-www-form-urlencoded"
    'oHttp.setRequestHeader "Content-Type", "text/xml"
    'oHttp.setRequestHeader "Content-Type", "multipart/form-data"
      
  
     'oHttp.Open "GET", "http://www.amazon.com", False
   
       oHttp.Open "GET", strMyURL, False
      
    ' stick in your web page above , file type can be anything asp txt 
xml html jpeg zip etc.
    'depends partially on content type
    oHttp.setRequestHeader "Content-Type", 
"application/x-www-form-urlencoded"
    oHttp.send
   
 
    
     'check the feedback
     Debug.Print "Ready State =" & oHttp.readyState
     'normal state =4
     Debug.Print "Status =" & oHttp.status
     'normal status = 200
     Debug.Print "Status Text =" & oHttp.statusText
    ' Debug.Print oHttp.getAllResponseHeaders()
    'Debug.Print "Response Body =" & oHttp.responseBody
    ' Debug.Print "Response Body =" & StrConv(oHttp.responseBody, vbUnicode)
    'Debug.Print "Response Text =" & oHttp.responseText
    'Parse response text string here or send to file
    'create directory structure if not in existance
   ' CreateDirectoryStruct ("c:\Accesshtmlstealer")
   
    strFileName = "c:\Accesshtmlstealer\Amazon"
    strFileName = strFileName & Format(Now, "yyyymmddhhmmss") & ".txt"
   
    '   WriteFile strFileName, oHttp.responseText
     'Temporary storage
intfile = FreeFile()
'bData() = Inet1.OpenURL(strURL, icByteArray)
' The file will be saved in the temp folder with the name download.exe'
Open "c:\temp\downloadA.zip" For Binary Access Write As #intfile
'Put #intfile, , bData()
bData() = oHttp.responseBody
Put #intfile, , bData()
Close #intfile
   '
        Exit Sub
       
ErrorHandler:
        MsgBox Err.Description & vbCrLf & Err.Number
        '
        Resume Next
   
End Sub


Darren DICK wrote:

>Thanks to all who responded
>I will keep away from the WinHTTP object
>Some of my clients are still using Win 98 (And it's not even Second
>Edition<sigh>)
>
>Here is the scenario
>
>All I have is a text file that has a version number of that particular app.
>
>I want my apps to look for this text file - read the contents and see it
>says 6.00
>Now, if the current version of the app that is looking at this text file
>happens to be version 5.95 - 
>a download of a new version should occur.
>
>I just wanted to put this text file in a public place eg a web site
>
>I actually don't wanna download the text file - just read from it
>
>Simple right??
>
>Anyway back to the drawing board
>
>Again many thanks to those who responded
>
>I will be using the download code from Gustav - it looks cool Thanks Gustav
>
>See y'all
>
>Darren
>
>
>
>
>-----Original Message-----
>From: accessd-bounces at databaseadvisors.com
>[mailto:accessd-bounces at databaseadvisors.com] On Behalf Of MartyConnelly
>Sent: Sunday, 19 December 2004 3:41 AM
>To: Access Developers discussion and problem solving
>Subject: Re: [AccessD] A2003:Connect to a text file at a web address
>
>Sob.  But Microsoft initially said it was redistributable. But then  I
>didn't look for awhile, I have WinXP SP1 installed and the two versions
>WinHttp 5.0 and 5.1 coexist side by side WinXP SP2 has another version.
>For all the gory details
>http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winhttp/htt
>p/what_s_new_in_winhttp_5_1.asp
>
>Stuart McLachlan wrote:
>
>  
>
>>On 17 Dec 2004 at 9:25, MartyConnelly wrote:
>>
>> 
>>
>>    
>>
>>>You can also use this on Win2000 and higher This works for me using 
>>>WinHttp when the site uses basic authentication:
>>>There are some other winhttp methods you can use to get around server 
>>>proxies etc.
>>>
>>>       Dim objWinHttp as object
>>>       Dim strURL as string
>>>       Dim strHTML as string 'your returned file
>>>
>>>
>>>       strURL = "http://somesite.com"
>>>       Set objWinHttp = CreateObject("WinHttp.WinHttpRequest.5")
>>>
>>>   
>>>
>>>      
>>>
>>You have to be a bit careful here and it's not redistributable because 
>>there are different versiosn of WinHttp out there. Any of the following 
>>may be required on W2K/XP systems  ...Request.5 ...Request.5.1 or 
>>Request.5.1.1 you need to look at the exact version number when you create
>>    
>>
>the reference.
>  
>
>> 
>>
>>    
>>
>
>--
>Marty Connelly
>Victoria, B.C.
>Canada
>
>
>  
>

-- 
Marty Connelly
Victoria, B.C.
Canada





More information about the AccessD mailing list