[futurebasic] Re: [FB] FN URLDownload example

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : March 2005 : Group Archive : Group : All Groups

From: Robert Purves <robert.purves@...>
Date: Wed, 2 Mar 2005 00:15:34 +1300
David Cox wrote:

> I have look through all the FB examples, but cannot find a sample 
> program showing me how to download an HTML page. I don't need to view 
> it or download the graphics. I only want the text file. It needs to be 
> able to download any size file, even greater than 32K.
>
> Tedd gave me an excellent one using "fn URLSimpleDownload", but it 
> doesn't download the larger html files. Is there anyone who has 
> written one using "fn URLDownload", or something even better. My 
> routines then will rip all the html code and superfluous text out 
> leaving only the text wanted.


include "Tlbx URLAccess.Incl"

local fn SimpleDownLoadToHandle( url as str255, urlStatusPtr as ptr )
// Returns a handle to content of downloaded file
// The caller is responsible for disposing of this handle
dim contentH  as Handle
dim urlStatus as OSStatus

contentH = fn NewHandle( 0 ) // make empty handle block
long if contentH // made handle?
fn FBPStr2CStr( url ) // PString -> CString (a runtime routine)
urlStatus = fn URLSimpleDownload( url, #_nil, contentH, _nil, _nil, 
#_nil ) // attempt download
urlStatusPtr.nil& = urlStatus // pass error code back to caller
end if

end fn = contentH


dim @ contentH   as Handle
dim @ urlStatus  as OSStatus
dim url          as Str255

url = "http://blah.html"
contentH = fn SimpleDownLoadToHandle( url, @urlStatus )
long if ( urlStatus == _noErr )
    ...succeeded...
end if
def DisposeH( contentH )


Robert P.